descargar pdf y fotos
This commit is contained in:
+1
@@ -0,0 +1 @@
|
|||||||
|
../crc-32/bin/crc32.njs
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../glob/dist/esm/bin.mjs
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../mime/cli.js
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../mkdirp/bin/cmd.js
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../which/bin/node-which
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../semver/bin/semver.js
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
../xlsx/bin/xlsx.njs
|
||||||
+3102
File diff suppressed because it is too large
Load Diff
+46
@@ -0,0 +1,46 @@
|
|||||||
|
# `@img/sharp-libvips-linux-x64`
|
||||||
|
|
||||||
|
Prebuilt libvips and dependencies for use with sharp on Linux (glibc) x64.
|
||||||
|
|
||||||
|
## Licensing
|
||||||
|
|
||||||
|
This software contains third-party libraries
|
||||||
|
used under the terms of the following licences:
|
||||||
|
|
||||||
|
| Library | Used under the terms of |
|
||||||
|
|---------------|-----------------------------------------------------------------------------------------------------------|
|
||||||
|
| aom | BSD 2-Clause + [Alliance for Open Media Patent License 1.0](https://aomedia.org/license/patent-license/) |
|
||||||
|
| cairo | Mozilla Public License 2.0 |
|
||||||
|
| cgif | MIT Licence |
|
||||||
|
| expat | MIT Licence |
|
||||||
|
| fontconfig | [fontconfig Licence](https://gitlab.freedesktop.org/fontconfig/fontconfig/blob/main/COPYING) (BSD-like) |
|
||||||
|
| freetype | [freetype Licence](https://git.savannah.gnu.org/cgit/freetype/freetype2.git/tree/docs/FTL.TXT) (BSD-like) |
|
||||||
|
| fribidi | LGPLv3 |
|
||||||
|
| glib | LGPLv3 |
|
||||||
|
| harfbuzz | MIT Licence |
|
||||||
|
| highway | Apache-2.0 License, BSD 3-Clause |
|
||||||
|
| lcms | MIT Licence |
|
||||||
|
| libarchive | BSD 2-Clause |
|
||||||
|
| libexif | LGPLv3 |
|
||||||
|
| libffi | MIT Licence |
|
||||||
|
| libheif | LGPLv3 |
|
||||||
|
| libimagequant | [BSD 2-Clause](https://github.com/lovell/libimagequant/blob/main/COPYRIGHT) |
|
||||||
|
| libnsgif | MIT Licence |
|
||||||
|
| libpng | [libpng License](https://github.com/pnggroup/libpng/blob/master/LICENSE) |
|
||||||
|
| librsvg | LGPLv3 |
|
||||||
|
| libspng | [BSD 2-Clause, libpng License](https://github.com/randy408/libspng/blob/master/LICENSE) |
|
||||||
|
| libtiff | [libtiff License](https://gitlab.com/libtiff/libtiff/blob/master/LICENSE.md) (BSD-like) |
|
||||||
|
| libvips | LGPLv3 |
|
||||||
|
| libwebp | New BSD License |
|
||||||
|
| libxml2 | MIT Licence |
|
||||||
|
| mozjpeg | [zlib License, IJG License, BSD-3-Clause](https://github.com/mozilla/mozjpeg/blob/master/LICENSE.md) |
|
||||||
|
| pango | LGPLv3 |
|
||||||
|
| pixman | MIT Licence |
|
||||||
|
| proxy-libintl | LGPLv3 |
|
||||||
|
| zlib-ng | [zlib Licence](https://github.com/zlib-ng/zlib-ng/blob/develop/LICENSE.md) |
|
||||||
|
|
||||||
|
Use of libraries under the terms of the LGPLv3 is via the
|
||||||
|
"any later version" clause of the LGPLv2 or LGPLv2.1.
|
||||||
|
|
||||||
|
Please report any errors or omissions via
|
||||||
|
https://github.com/lovell/sharp-libvips/issues/new
|
||||||
Generated
Vendored
+221
@@ -0,0 +1,221 @@
|
|||||||
|
/* glibconfig.h
|
||||||
|
*
|
||||||
|
* This is a generated file. Please modify 'glibconfig.h.in'
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __GLIBCONFIG_H__
|
||||||
|
#define __GLIBCONFIG_H__
|
||||||
|
|
||||||
|
#include <glib/gmacros.h>
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
#include <float.h>
|
||||||
|
#define GLIB_HAVE_ALLOCA_H
|
||||||
|
|
||||||
|
#define GLIB_STATIC_COMPILATION 1
|
||||||
|
#define GOBJECT_STATIC_COMPILATION 1
|
||||||
|
#define GIO_STATIC_COMPILATION 1
|
||||||
|
#define GMODULE_STATIC_COMPILATION 1
|
||||||
|
#define GI_STATIC_COMPILATION 1
|
||||||
|
#define G_INTL_STATIC_COMPILATION 1
|
||||||
|
#define FFI_STATIC_BUILD 1
|
||||||
|
|
||||||
|
/* Specifies that GLib's g_print*() functions wrap the
|
||||||
|
* system printf functions. This is useful to know, for example,
|
||||||
|
* when using glibc's register_printf_function().
|
||||||
|
*/
|
||||||
|
#define GLIB_USING_SYSTEM_PRINTF
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define G_MINFLOAT FLT_MIN
|
||||||
|
#define G_MAXFLOAT FLT_MAX
|
||||||
|
#define G_MINDOUBLE DBL_MIN
|
||||||
|
#define G_MAXDOUBLE DBL_MAX
|
||||||
|
#define G_MINSHORT SHRT_MIN
|
||||||
|
#define G_MAXSHORT SHRT_MAX
|
||||||
|
#define G_MAXUSHORT USHRT_MAX
|
||||||
|
#define G_MININT INT_MIN
|
||||||
|
#define G_MAXINT INT_MAX
|
||||||
|
#define G_MAXUINT UINT_MAX
|
||||||
|
#define G_MINLONG LONG_MIN
|
||||||
|
#define G_MAXLONG LONG_MAX
|
||||||
|
#define G_MAXULONG ULONG_MAX
|
||||||
|
|
||||||
|
typedef signed char gint8;
|
||||||
|
typedef unsigned char guint8;
|
||||||
|
|
||||||
|
typedef signed short gint16;
|
||||||
|
typedef unsigned short guint16;
|
||||||
|
|
||||||
|
#define G_GINT16_MODIFIER "h"
|
||||||
|
#define G_GINT16_FORMAT "hi"
|
||||||
|
#define G_GUINT16_FORMAT "hu"
|
||||||
|
|
||||||
|
|
||||||
|
typedef signed int gint32;
|
||||||
|
typedef unsigned int guint32;
|
||||||
|
|
||||||
|
#define G_GINT32_MODIFIER ""
|
||||||
|
#define G_GINT32_FORMAT "i"
|
||||||
|
#define G_GUINT32_FORMAT "u"
|
||||||
|
|
||||||
|
|
||||||
|
#define G_HAVE_GINT64 1 /* deprecated, always true */
|
||||||
|
|
||||||
|
typedef signed long gint64;
|
||||||
|
typedef unsigned long guint64;
|
||||||
|
|
||||||
|
#define G_GINT64_CONSTANT(val) (val##L)
|
||||||
|
#define G_GUINT64_CONSTANT(val) (val##UL)
|
||||||
|
|
||||||
|
#define G_GINT64_MODIFIER "l"
|
||||||
|
#define G_GINT64_FORMAT "li"
|
||||||
|
#define G_GUINT64_FORMAT "lu"
|
||||||
|
|
||||||
|
|
||||||
|
#define GLIB_SIZEOF_VOID_P 8
|
||||||
|
#define GLIB_SIZEOF_LONG 8
|
||||||
|
#define GLIB_SIZEOF_SIZE_T 8
|
||||||
|
#define GLIB_SIZEOF_SSIZE_T 8
|
||||||
|
|
||||||
|
typedef signed long gssize;
|
||||||
|
typedef unsigned long gsize;
|
||||||
|
#define G_GSIZE_MODIFIER "l"
|
||||||
|
#define G_GSSIZE_MODIFIER "l"
|
||||||
|
#define G_GSIZE_FORMAT "lu"
|
||||||
|
#define G_GSSIZE_FORMAT "li"
|
||||||
|
|
||||||
|
#define G_MAXSIZE G_MAXULONG
|
||||||
|
#define G_MINSSIZE G_MINLONG
|
||||||
|
#define G_MAXSSIZE G_MAXLONG
|
||||||
|
|
||||||
|
typedef gint64 goffset;
|
||||||
|
#define G_MINOFFSET G_MININT64
|
||||||
|
#define G_MAXOFFSET G_MAXINT64
|
||||||
|
|
||||||
|
#define G_GOFFSET_MODIFIER G_GINT64_MODIFIER
|
||||||
|
#define G_GOFFSET_FORMAT G_GINT64_FORMAT
|
||||||
|
#define G_GOFFSET_CONSTANT(val) G_GINT64_CONSTANT(val)
|
||||||
|
|
||||||
|
#define G_POLLFD_FORMAT "%d"
|
||||||
|
|
||||||
|
#define GPOINTER_TO_INT(p) ((gint) (glong) (p))
|
||||||
|
#define GPOINTER_TO_UINT(p) ((guint) (gulong) (p))
|
||||||
|
|
||||||
|
#define GINT_TO_POINTER(i) ((gpointer) (glong) (i))
|
||||||
|
#define GUINT_TO_POINTER(u) ((gpointer) (gulong) (u))
|
||||||
|
|
||||||
|
typedef signed long gintptr;
|
||||||
|
typedef unsigned long guintptr;
|
||||||
|
|
||||||
|
#define G_GINTPTR_MODIFIER "l"
|
||||||
|
#define G_GINTPTR_FORMAT "li"
|
||||||
|
#define G_GUINTPTR_FORMAT "lu"
|
||||||
|
|
||||||
|
#define GLIB_MAJOR_VERSION 2
|
||||||
|
#define GLIB_MINOR_VERSION 81
|
||||||
|
#define GLIB_MICRO_VERSION 1
|
||||||
|
|
||||||
|
#define G_OS_UNIX
|
||||||
|
|
||||||
|
#define G_VA_COPY va_copy
|
||||||
|
|
||||||
|
#define G_VA_COPY_AS_ARRAY 1
|
||||||
|
|
||||||
|
#define G_HAVE_ISO_VARARGS 1
|
||||||
|
|
||||||
|
/* gcc-2.95.x supports both gnu style and ISO varargs, but if -ansi
|
||||||
|
* is passed ISO vararg support is turned off, and there is no work
|
||||||
|
* around to turn it on, so we unconditionally turn it off.
|
||||||
|
*/
|
||||||
|
#if __GNUC__ == 2 && __GNUC_MINOR__ == 95
|
||||||
|
# undef G_HAVE_ISO_VARARGS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define G_HAVE_GROWING_STACK 0
|
||||||
|
|
||||||
|
#ifndef _MSC_VER
|
||||||
|
# define G_HAVE_GNUC_VARARGS 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
|
||||||
|
#define G_GNUC_INTERNAL __attribute__((visibility("hidden")))
|
||||||
|
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
|
||||||
|
#define G_GNUC_INTERNAL __hidden
|
||||||
|
#elif defined (__GNUC__) && defined (G_HAVE_GNUC_VISIBILITY)
|
||||||
|
#define G_GNUC_INTERNAL __attribute__((visibility("hidden")))
|
||||||
|
#else
|
||||||
|
#define G_GNUC_INTERNAL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define G_THREADS_ENABLED
|
||||||
|
#define G_THREADS_IMPL_POSIX
|
||||||
|
|
||||||
|
#define G_ATOMIC_LOCK_FREE
|
||||||
|
|
||||||
|
#define GINT16_TO_LE(val) ((gint16) (val))
|
||||||
|
#define GUINT16_TO_LE(val) ((guint16) (val))
|
||||||
|
#define GINT16_TO_BE(val) ((gint16) GUINT16_SWAP_LE_BE (val))
|
||||||
|
#define GUINT16_TO_BE(val) (GUINT16_SWAP_LE_BE (val))
|
||||||
|
|
||||||
|
#define GINT32_TO_LE(val) ((gint32) (val))
|
||||||
|
#define GUINT32_TO_LE(val) ((guint32) (val))
|
||||||
|
#define GINT32_TO_BE(val) ((gint32) GUINT32_SWAP_LE_BE (val))
|
||||||
|
#define GUINT32_TO_BE(val) (GUINT32_SWAP_LE_BE (val))
|
||||||
|
|
||||||
|
#define GINT64_TO_LE(val) ((gint64) (val))
|
||||||
|
#define GUINT64_TO_LE(val) ((guint64) (val))
|
||||||
|
#define GINT64_TO_BE(val) ((gint64) GUINT64_SWAP_LE_BE (val))
|
||||||
|
#define GUINT64_TO_BE(val) (GUINT64_SWAP_LE_BE (val))
|
||||||
|
|
||||||
|
#define GLONG_TO_LE(val) ((glong) GINT64_TO_LE (val))
|
||||||
|
#define GULONG_TO_LE(val) ((gulong) GUINT64_TO_LE (val))
|
||||||
|
#define GLONG_TO_BE(val) ((glong) GINT64_TO_BE (val))
|
||||||
|
#define GULONG_TO_BE(val) ((gulong) GUINT64_TO_BE (val))
|
||||||
|
#define GINT_TO_LE(val) ((gint) GINT32_TO_LE (val))
|
||||||
|
#define GUINT_TO_LE(val) ((guint) GUINT32_TO_LE (val))
|
||||||
|
#define GINT_TO_BE(val) ((gint) GINT32_TO_BE (val))
|
||||||
|
#define GUINT_TO_BE(val) ((guint) GUINT32_TO_BE (val))
|
||||||
|
#define GSIZE_TO_LE(val) ((gsize) GUINT64_TO_LE (val))
|
||||||
|
#define GSSIZE_TO_LE(val) ((gssize) GINT64_TO_LE (val))
|
||||||
|
#define GSIZE_TO_BE(val) ((gsize) GUINT64_TO_BE (val))
|
||||||
|
#define GSSIZE_TO_BE(val) ((gssize) GINT64_TO_BE (val))
|
||||||
|
#define G_BYTE_ORDER G_LITTLE_ENDIAN
|
||||||
|
|
||||||
|
#define GLIB_SYSDEF_POLLIN =1
|
||||||
|
#define GLIB_SYSDEF_POLLOUT =4
|
||||||
|
#define GLIB_SYSDEF_POLLPRI =2
|
||||||
|
#define GLIB_SYSDEF_POLLHUP =16
|
||||||
|
#define GLIB_SYSDEF_POLLERR =8
|
||||||
|
#define GLIB_SYSDEF_POLLNVAL =32
|
||||||
|
|
||||||
|
/* No way to disable deprecation warnings for macros, so only emit deprecation
|
||||||
|
* warnings on platforms where usage of this macro is broken */
|
||||||
|
#if defined(__APPLE__) || defined(_MSC_VER) || defined(__CYGWIN__)
|
||||||
|
#define G_MODULE_SUFFIX "so" GLIB_DEPRECATED_MACRO_IN_2_76
|
||||||
|
#else
|
||||||
|
#define G_MODULE_SUFFIX "so"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef int GPid;
|
||||||
|
#define G_PID_FORMAT "i"
|
||||||
|
|
||||||
|
#define GLIB_SYSDEF_AF_UNIX 1
|
||||||
|
#define GLIB_SYSDEF_AF_INET 2
|
||||||
|
#define GLIB_SYSDEF_AF_INET6 10
|
||||||
|
|
||||||
|
#define GLIB_SYSDEF_MSG_OOB 1
|
||||||
|
#define GLIB_SYSDEF_MSG_PEEK 2
|
||||||
|
#define GLIB_SYSDEF_MSG_DONTROUTE 4
|
||||||
|
|
||||||
|
#define G_DIR_SEPARATOR '/'
|
||||||
|
#define G_DIR_SEPARATOR_S "/"
|
||||||
|
#define G_SEARCHPATH_SEPARATOR ':'
|
||||||
|
#define G_SEARCHPATH_SEPARATOR_S ":"
|
||||||
|
|
||||||
|
#undef G_HAVE_FREE_SIZED
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* __GLIBCONFIG_H__ */
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
module.exports = __dirname;
|
||||||
BIN
Binary file not shown.
+42
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"name": "@img/sharp-libvips-linux-x64",
|
||||||
|
"version": "1.0.4",
|
||||||
|
"description": "Prebuilt libvips and dependencies for use with sharp on Linux (glibc) x64",
|
||||||
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/lovell/sharp-libvips.git",
|
||||||
|
"directory": "npm/linux-x64"
|
||||||
|
},
|
||||||
|
"license": "LGPL-3.0-or-later",
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
|
"preferUnplugged": true,
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"lib",
|
||||||
|
"versions.json"
|
||||||
|
],
|
||||||
|
"type": "commonjs",
|
||||||
|
"exports": {
|
||||||
|
"./lib": "./lib/index.js",
|
||||||
|
"./package": "./package.json",
|
||||||
|
"./versions": "./versions.json"
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"glibc": ">=2.26"
|
||||||
|
},
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"libc": [
|
||||||
|
"glibc"
|
||||||
|
],
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
]
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"aom": "3.9.1",
|
||||||
|
"archive": "3.7.4",
|
||||||
|
"cairo": "1.18.0",
|
||||||
|
"cgif": "0.4.1",
|
||||||
|
"exif": "0.6.24",
|
||||||
|
"expat": "2.6.2",
|
||||||
|
"ffi": "3.4.6",
|
||||||
|
"fontconfig": "2.15.0",
|
||||||
|
"freetype": "2.13.2",
|
||||||
|
"fribidi": "1.0.15",
|
||||||
|
"glib": "2.81.1",
|
||||||
|
"harfbuzz": "9.0.0",
|
||||||
|
"heif": "1.18.2",
|
||||||
|
"highway": "1.2.0",
|
||||||
|
"imagequant": "2.4.1",
|
||||||
|
"lcms": "2.16",
|
||||||
|
"mozjpeg": "4.1.5",
|
||||||
|
"pango": "1.54.0",
|
||||||
|
"pixman": "0.43.4",
|
||||||
|
"png": "1.6.43",
|
||||||
|
"proxy-libintl": "0.4",
|
||||||
|
"rsvg": "2.58.93",
|
||||||
|
"spng": "0.7.4",
|
||||||
|
"tiff": "4.6.0",
|
||||||
|
"vips": "8.15.3",
|
||||||
|
"webp": "1.4.0",
|
||||||
|
"xml": "2.13.3",
|
||||||
|
"zlib-ng": "2.2.1"
|
||||||
|
}
|
||||||
+46
@@ -0,0 +1,46 @@
|
|||||||
|
# `@img/sharp-libvips-linuxmusl-x64`
|
||||||
|
|
||||||
|
Prebuilt libvips and dependencies for use with sharp on Linux (musl) x64.
|
||||||
|
|
||||||
|
## Licensing
|
||||||
|
|
||||||
|
This software contains third-party libraries
|
||||||
|
used under the terms of the following licences:
|
||||||
|
|
||||||
|
| Library | Used under the terms of |
|
||||||
|
|---------------|-----------------------------------------------------------------------------------------------------------|
|
||||||
|
| aom | BSD 2-Clause + [Alliance for Open Media Patent License 1.0](https://aomedia.org/license/patent-license/) |
|
||||||
|
| cairo | Mozilla Public License 2.0 |
|
||||||
|
| cgif | MIT Licence |
|
||||||
|
| expat | MIT Licence |
|
||||||
|
| fontconfig | [fontconfig Licence](https://gitlab.freedesktop.org/fontconfig/fontconfig/blob/main/COPYING) (BSD-like) |
|
||||||
|
| freetype | [freetype Licence](https://git.savannah.gnu.org/cgit/freetype/freetype2.git/tree/docs/FTL.TXT) (BSD-like) |
|
||||||
|
| fribidi | LGPLv3 |
|
||||||
|
| glib | LGPLv3 |
|
||||||
|
| harfbuzz | MIT Licence |
|
||||||
|
| highway | Apache-2.0 License, BSD 3-Clause |
|
||||||
|
| lcms | MIT Licence |
|
||||||
|
| libarchive | BSD 2-Clause |
|
||||||
|
| libexif | LGPLv3 |
|
||||||
|
| libffi | MIT Licence |
|
||||||
|
| libheif | LGPLv3 |
|
||||||
|
| libimagequant | [BSD 2-Clause](https://github.com/lovell/libimagequant/blob/main/COPYRIGHT) |
|
||||||
|
| libnsgif | MIT Licence |
|
||||||
|
| libpng | [libpng License](https://github.com/pnggroup/libpng/blob/master/LICENSE) |
|
||||||
|
| librsvg | LGPLv3 |
|
||||||
|
| libspng | [BSD 2-Clause, libpng License](https://github.com/randy408/libspng/blob/master/LICENSE) |
|
||||||
|
| libtiff | [libtiff License](https://gitlab.com/libtiff/libtiff/blob/master/LICENSE.md) (BSD-like) |
|
||||||
|
| libvips | LGPLv3 |
|
||||||
|
| libwebp | New BSD License |
|
||||||
|
| libxml2 | MIT Licence |
|
||||||
|
| mozjpeg | [zlib License, IJG License, BSD-3-Clause](https://github.com/mozilla/mozjpeg/blob/master/LICENSE.md) |
|
||||||
|
| pango | LGPLv3 |
|
||||||
|
| pixman | MIT Licence |
|
||||||
|
| proxy-libintl | LGPLv3 |
|
||||||
|
| zlib-ng | [zlib Licence](https://github.com/zlib-ng/zlib-ng/blob/develop/LICENSE.md) |
|
||||||
|
|
||||||
|
Use of libraries under the terms of the LGPLv3 is via the
|
||||||
|
"any later version" clause of the LGPLv2 or LGPLv2.1.
|
||||||
|
|
||||||
|
Please report any errors or omissions via
|
||||||
|
https://github.com/lovell/sharp-libvips/issues/new
|
||||||
Generated
Vendored
+221
@@ -0,0 +1,221 @@
|
|||||||
|
/* glibconfig.h
|
||||||
|
*
|
||||||
|
* This is a generated file. Please modify 'glibconfig.h.in'
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __GLIBCONFIG_H__
|
||||||
|
#define __GLIBCONFIG_H__
|
||||||
|
|
||||||
|
#include <glib/gmacros.h>
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
#include <float.h>
|
||||||
|
#define GLIB_HAVE_ALLOCA_H
|
||||||
|
|
||||||
|
#define GLIB_STATIC_COMPILATION 1
|
||||||
|
#define GOBJECT_STATIC_COMPILATION 1
|
||||||
|
#define GIO_STATIC_COMPILATION 1
|
||||||
|
#define GMODULE_STATIC_COMPILATION 1
|
||||||
|
#define GI_STATIC_COMPILATION 1
|
||||||
|
#define G_INTL_STATIC_COMPILATION 1
|
||||||
|
#define FFI_STATIC_BUILD 1
|
||||||
|
|
||||||
|
/* Specifies that GLib's g_print*() functions wrap the
|
||||||
|
* system printf functions. This is useful to know, for example,
|
||||||
|
* when using glibc's register_printf_function().
|
||||||
|
*/
|
||||||
|
#define GLIB_USING_SYSTEM_PRINTF
|
||||||
|
|
||||||
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
|
#define G_MINFLOAT FLT_MIN
|
||||||
|
#define G_MAXFLOAT FLT_MAX
|
||||||
|
#define G_MINDOUBLE DBL_MIN
|
||||||
|
#define G_MAXDOUBLE DBL_MAX
|
||||||
|
#define G_MINSHORT SHRT_MIN
|
||||||
|
#define G_MAXSHORT SHRT_MAX
|
||||||
|
#define G_MAXUSHORT USHRT_MAX
|
||||||
|
#define G_MININT INT_MIN
|
||||||
|
#define G_MAXINT INT_MAX
|
||||||
|
#define G_MAXUINT UINT_MAX
|
||||||
|
#define G_MINLONG LONG_MIN
|
||||||
|
#define G_MAXLONG LONG_MAX
|
||||||
|
#define G_MAXULONG ULONG_MAX
|
||||||
|
|
||||||
|
typedef signed char gint8;
|
||||||
|
typedef unsigned char guint8;
|
||||||
|
|
||||||
|
typedef signed short gint16;
|
||||||
|
typedef unsigned short guint16;
|
||||||
|
|
||||||
|
#define G_GINT16_MODIFIER "h"
|
||||||
|
#define G_GINT16_FORMAT "hi"
|
||||||
|
#define G_GUINT16_FORMAT "hu"
|
||||||
|
|
||||||
|
|
||||||
|
typedef signed int gint32;
|
||||||
|
typedef unsigned int guint32;
|
||||||
|
|
||||||
|
#define G_GINT32_MODIFIER ""
|
||||||
|
#define G_GINT32_FORMAT "i"
|
||||||
|
#define G_GUINT32_FORMAT "u"
|
||||||
|
|
||||||
|
|
||||||
|
#define G_HAVE_GINT64 1 /* deprecated, always true */
|
||||||
|
|
||||||
|
typedef signed long gint64;
|
||||||
|
typedef unsigned long guint64;
|
||||||
|
|
||||||
|
#define G_GINT64_CONSTANT(val) (val##L)
|
||||||
|
#define G_GUINT64_CONSTANT(val) (val##UL)
|
||||||
|
|
||||||
|
#define G_GINT64_MODIFIER "l"
|
||||||
|
#define G_GINT64_FORMAT "li"
|
||||||
|
#define G_GUINT64_FORMAT "lu"
|
||||||
|
|
||||||
|
|
||||||
|
#define GLIB_SIZEOF_VOID_P 8
|
||||||
|
#define GLIB_SIZEOF_LONG 8
|
||||||
|
#define GLIB_SIZEOF_SIZE_T 8
|
||||||
|
#define GLIB_SIZEOF_SSIZE_T 8
|
||||||
|
|
||||||
|
typedef signed long gssize;
|
||||||
|
typedef unsigned long gsize;
|
||||||
|
#define G_GSIZE_MODIFIER "l"
|
||||||
|
#define G_GSSIZE_MODIFIER "l"
|
||||||
|
#define G_GSIZE_FORMAT "lu"
|
||||||
|
#define G_GSSIZE_FORMAT "li"
|
||||||
|
|
||||||
|
#define G_MAXSIZE G_MAXULONG
|
||||||
|
#define G_MINSSIZE G_MINLONG
|
||||||
|
#define G_MAXSSIZE G_MAXLONG
|
||||||
|
|
||||||
|
typedef gint64 goffset;
|
||||||
|
#define G_MINOFFSET G_MININT64
|
||||||
|
#define G_MAXOFFSET G_MAXINT64
|
||||||
|
|
||||||
|
#define G_GOFFSET_MODIFIER G_GINT64_MODIFIER
|
||||||
|
#define G_GOFFSET_FORMAT G_GINT64_FORMAT
|
||||||
|
#define G_GOFFSET_CONSTANT(val) G_GINT64_CONSTANT(val)
|
||||||
|
|
||||||
|
#define G_POLLFD_FORMAT "%d"
|
||||||
|
|
||||||
|
#define GPOINTER_TO_INT(p) ((gint) (glong) (p))
|
||||||
|
#define GPOINTER_TO_UINT(p) ((guint) (gulong) (p))
|
||||||
|
|
||||||
|
#define GINT_TO_POINTER(i) ((gpointer) (glong) (i))
|
||||||
|
#define GUINT_TO_POINTER(u) ((gpointer) (gulong) (u))
|
||||||
|
|
||||||
|
typedef signed long gintptr;
|
||||||
|
typedef unsigned long guintptr;
|
||||||
|
|
||||||
|
#define G_GINTPTR_MODIFIER "l"
|
||||||
|
#define G_GINTPTR_FORMAT "li"
|
||||||
|
#define G_GUINTPTR_FORMAT "lu"
|
||||||
|
|
||||||
|
#define GLIB_MAJOR_VERSION 2
|
||||||
|
#define GLIB_MINOR_VERSION 81
|
||||||
|
#define GLIB_MICRO_VERSION 1
|
||||||
|
|
||||||
|
#define G_OS_UNIX
|
||||||
|
|
||||||
|
#define G_VA_COPY va_copy
|
||||||
|
|
||||||
|
#define G_VA_COPY_AS_ARRAY 1
|
||||||
|
|
||||||
|
#define G_HAVE_ISO_VARARGS 1
|
||||||
|
|
||||||
|
/* gcc-2.95.x supports both gnu style and ISO varargs, but if -ansi
|
||||||
|
* is passed ISO vararg support is turned off, and there is no work
|
||||||
|
* around to turn it on, so we unconditionally turn it off.
|
||||||
|
*/
|
||||||
|
#if __GNUC__ == 2 && __GNUC_MINOR__ == 95
|
||||||
|
# undef G_HAVE_ISO_VARARGS
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define G_HAVE_GROWING_STACK 0
|
||||||
|
|
||||||
|
#ifndef _MSC_VER
|
||||||
|
# define G_HAVE_GNUC_VARARGS 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590)
|
||||||
|
#define G_GNUC_INTERNAL __attribute__((visibility("hidden")))
|
||||||
|
#elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x550)
|
||||||
|
#define G_GNUC_INTERNAL __hidden
|
||||||
|
#elif defined (__GNUC__) && defined (G_HAVE_GNUC_VISIBILITY)
|
||||||
|
#define G_GNUC_INTERNAL __attribute__((visibility("hidden")))
|
||||||
|
#else
|
||||||
|
#define G_GNUC_INTERNAL
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define G_THREADS_ENABLED
|
||||||
|
#define G_THREADS_IMPL_POSIX
|
||||||
|
|
||||||
|
#define G_ATOMIC_LOCK_FREE
|
||||||
|
|
||||||
|
#define GINT16_TO_LE(val) ((gint16) (val))
|
||||||
|
#define GUINT16_TO_LE(val) ((guint16) (val))
|
||||||
|
#define GINT16_TO_BE(val) ((gint16) GUINT16_SWAP_LE_BE (val))
|
||||||
|
#define GUINT16_TO_BE(val) (GUINT16_SWAP_LE_BE (val))
|
||||||
|
|
||||||
|
#define GINT32_TO_LE(val) ((gint32) (val))
|
||||||
|
#define GUINT32_TO_LE(val) ((guint32) (val))
|
||||||
|
#define GINT32_TO_BE(val) ((gint32) GUINT32_SWAP_LE_BE (val))
|
||||||
|
#define GUINT32_TO_BE(val) (GUINT32_SWAP_LE_BE (val))
|
||||||
|
|
||||||
|
#define GINT64_TO_LE(val) ((gint64) (val))
|
||||||
|
#define GUINT64_TO_LE(val) ((guint64) (val))
|
||||||
|
#define GINT64_TO_BE(val) ((gint64) GUINT64_SWAP_LE_BE (val))
|
||||||
|
#define GUINT64_TO_BE(val) (GUINT64_SWAP_LE_BE (val))
|
||||||
|
|
||||||
|
#define GLONG_TO_LE(val) ((glong) GINT64_TO_LE (val))
|
||||||
|
#define GULONG_TO_LE(val) ((gulong) GUINT64_TO_LE (val))
|
||||||
|
#define GLONG_TO_BE(val) ((glong) GINT64_TO_BE (val))
|
||||||
|
#define GULONG_TO_BE(val) ((gulong) GUINT64_TO_BE (val))
|
||||||
|
#define GINT_TO_LE(val) ((gint) GINT32_TO_LE (val))
|
||||||
|
#define GUINT_TO_LE(val) ((guint) GUINT32_TO_LE (val))
|
||||||
|
#define GINT_TO_BE(val) ((gint) GINT32_TO_BE (val))
|
||||||
|
#define GUINT_TO_BE(val) ((guint) GUINT32_TO_BE (val))
|
||||||
|
#define GSIZE_TO_LE(val) ((gsize) GUINT64_TO_LE (val))
|
||||||
|
#define GSSIZE_TO_LE(val) ((gssize) GINT64_TO_LE (val))
|
||||||
|
#define GSIZE_TO_BE(val) ((gsize) GUINT64_TO_BE (val))
|
||||||
|
#define GSSIZE_TO_BE(val) ((gssize) GINT64_TO_BE (val))
|
||||||
|
#define G_BYTE_ORDER G_LITTLE_ENDIAN
|
||||||
|
|
||||||
|
#define GLIB_SYSDEF_POLLIN =1
|
||||||
|
#define GLIB_SYSDEF_POLLOUT =4
|
||||||
|
#define GLIB_SYSDEF_POLLPRI =2
|
||||||
|
#define GLIB_SYSDEF_POLLHUP =16
|
||||||
|
#define GLIB_SYSDEF_POLLERR =8
|
||||||
|
#define GLIB_SYSDEF_POLLNVAL =32
|
||||||
|
|
||||||
|
/* No way to disable deprecation warnings for macros, so only emit deprecation
|
||||||
|
* warnings on platforms where usage of this macro is broken */
|
||||||
|
#if defined(__APPLE__) || defined(_MSC_VER) || defined(__CYGWIN__)
|
||||||
|
#define G_MODULE_SUFFIX "so" GLIB_DEPRECATED_MACRO_IN_2_76
|
||||||
|
#else
|
||||||
|
#define G_MODULE_SUFFIX "so"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef int GPid;
|
||||||
|
#define G_PID_FORMAT "i"
|
||||||
|
|
||||||
|
#define GLIB_SYSDEF_AF_UNIX 1
|
||||||
|
#define GLIB_SYSDEF_AF_INET 2
|
||||||
|
#define GLIB_SYSDEF_AF_INET6 10
|
||||||
|
|
||||||
|
#define GLIB_SYSDEF_MSG_OOB 1
|
||||||
|
#define GLIB_SYSDEF_MSG_PEEK 2
|
||||||
|
#define GLIB_SYSDEF_MSG_DONTROUTE 4
|
||||||
|
|
||||||
|
#define G_DIR_SEPARATOR '/'
|
||||||
|
#define G_DIR_SEPARATOR_S "/"
|
||||||
|
#define G_SEARCHPATH_SEPARATOR ':'
|
||||||
|
#define G_SEARCHPATH_SEPARATOR_S ":"
|
||||||
|
|
||||||
|
#undef G_HAVE_FREE_SIZED
|
||||||
|
|
||||||
|
G_END_DECLS
|
||||||
|
|
||||||
|
#endif /* __GLIBCONFIG_H__ */
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
module.exports = __dirname;
|
||||||
BIN
Binary file not shown.
+42
@@ -0,0 +1,42 @@
|
|||||||
|
{
|
||||||
|
"name": "@img/sharp-libvips-linuxmusl-x64",
|
||||||
|
"version": "1.0.4",
|
||||||
|
"description": "Prebuilt libvips and dependencies for use with sharp on Linux (musl) x64",
|
||||||
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/lovell/sharp-libvips.git",
|
||||||
|
"directory": "npm/linuxmusl-x64"
|
||||||
|
},
|
||||||
|
"license": "LGPL-3.0-or-later",
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
|
"preferUnplugged": true,
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"lib",
|
||||||
|
"versions.json"
|
||||||
|
],
|
||||||
|
"type": "commonjs",
|
||||||
|
"exports": {
|
||||||
|
"./lib": "./lib/index.js",
|
||||||
|
"./package": "./package.json",
|
||||||
|
"./versions": "./versions.json"
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"musl": ">=1.2.2"
|
||||||
|
},
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"libc": [
|
||||||
|
"musl"
|
||||||
|
],
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
]
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"aom": "3.9.1",
|
||||||
|
"archive": "3.7.4",
|
||||||
|
"cairo": "1.18.0",
|
||||||
|
"cgif": "0.4.1",
|
||||||
|
"exif": "0.6.24",
|
||||||
|
"expat": "2.6.2",
|
||||||
|
"ffi": "3.4.6",
|
||||||
|
"fontconfig": "2.15.0",
|
||||||
|
"freetype": "2.13.2",
|
||||||
|
"fribidi": "1.0.15",
|
||||||
|
"glib": "2.81.1",
|
||||||
|
"harfbuzz": "9.0.0",
|
||||||
|
"heif": "1.18.2",
|
||||||
|
"highway": "1.2.0",
|
||||||
|
"imagequant": "2.4.1",
|
||||||
|
"lcms": "2.16",
|
||||||
|
"mozjpeg": "4.1.5",
|
||||||
|
"pango": "1.54.0",
|
||||||
|
"pixman": "0.43.4",
|
||||||
|
"png": "1.6.43",
|
||||||
|
"proxy-libintl": "0.4",
|
||||||
|
"rsvg": "2.58.93",
|
||||||
|
"spng": "0.7.4",
|
||||||
|
"tiff": "4.6.0",
|
||||||
|
"vips": "8.15.3",
|
||||||
|
"webp": "1.4.0",
|
||||||
|
"xml": "2.13.3",
|
||||||
|
"zlib-ng": "2.2.1"
|
||||||
|
}
|
||||||
+191
@@ -0,0 +1,191 @@
|
|||||||
|
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:
|
||||||
|
|
||||||
|
You must give any other recipients of the Work or Derivative Works a copy of
|
||||||
|
this License; and
|
||||||
|
You must cause any modified files to carry prominent notices stating that You
|
||||||
|
changed the files; and
|
||||||
|
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
|
||||||
|
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
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following boilerplate
|
||||||
|
notice, with the fields enclosed by brackets "[]" replaced with your own
|
||||||
|
identifying information. (Don't include the brackets!) The text should be
|
||||||
|
enclosed in the appropriate comment syntax for the file format. We also
|
||||||
|
recommend that a file or class name and description of purpose be included on
|
||||||
|
the same "printed page" as the copyright notice for easier identification within
|
||||||
|
third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
# `@img/sharp-linux-x64`
|
||||||
|
|
||||||
|
Prebuilt sharp for use with Linux (glibc) x64.
|
||||||
|
|
||||||
|
## Licensing
|
||||||
|
|
||||||
|
Copyright 2013 Lovell Fuller and others.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
BIN
Binary file not shown.
+46
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"name": "@img/sharp-linux-x64",
|
||||||
|
"version": "0.33.5",
|
||||||
|
"description": "Prebuilt sharp for use with Linux (glibc) x64",
|
||||||
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/lovell/sharp.git",
|
||||||
|
"directory": "npm/linux-x64"
|
||||||
|
},
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
|
"preferUnplugged": true,
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-linux-x64": "1.0.4"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"lib"
|
||||||
|
],
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"type": "commonjs",
|
||||||
|
"exports": {
|
||||||
|
"./sharp.node": "./lib/sharp-linux-x64.node",
|
||||||
|
"./package": "./package.json"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"glibc": ">=2.26"
|
||||||
|
},
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"libc": [
|
||||||
|
"glibc"
|
||||||
|
],
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
]
|
||||||
|
}
|
||||||
+191
@@ -0,0 +1,191 @@
|
|||||||
|
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:
|
||||||
|
|
||||||
|
You must give any other recipients of the Work or Derivative Works a copy of
|
||||||
|
this License; and
|
||||||
|
You must cause any modified files to carry prominent notices stating that You
|
||||||
|
changed the files; and
|
||||||
|
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
|
||||||
|
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
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following boilerplate
|
||||||
|
notice, with the fields enclosed by brackets "[]" replaced with your own
|
||||||
|
identifying information. (Don't include the brackets!) The text should be
|
||||||
|
enclosed in the appropriate comment syntax for the file format. We also
|
||||||
|
recommend that a file or class name and description of purpose be included on
|
||||||
|
the same "printed page" as the copyright notice for easier identification within
|
||||||
|
third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
# `@img/sharp-linuxmusl-x64`
|
||||||
|
|
||||||
|
Prebuilt sharp for use with Linux (musl) x64.
|
||||||
|
|
||||||
|
## Licensing
|
||||||
|
|
||||||
|
Copyright 2013 Lovell Fuller and others.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
Generated
Vendored
Executable
BIN
Binary file not shown.
+46
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"name": "@img/sharp-linuxmusl-x64",
|
||||||
|
"version": "0.33.5",
|
||||||
|
"description": "Prebuilt sharp for use with Linux (musl) x64",
|
||||||
|
"author": "Lovell Fuller <npm@lovell.info>",
|
||||||
|
"homepage": "https://sharp.pixelplumbing.com",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/lovell/sharp.git",
|
||||||
|
"directory": "npm/linuxmusl-x64"
|
||||||
|
},
|
||||||
|
"license": "Apache-2.0",
|
||||||
|
"funding": {
|
||||||
|
"url": "https://opencollective.com/libvips"
|
||||||
|
},
|
||||||
|
"preferUnplugged": true,
|
||||||
|
"optionalDependencies": {
|
||||||
|
"@img/sharp-libvips-linuxmusl-x64": "1.0.4"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"lib"
|
||||||
|
],
|
||||||
|
"publishConfig": {
|
||||||
|
"access": "public"
|
||||||
|
},
|
||||||
|
"type": "commonjs",
|
||||||
|
"exports": {
|
||||||
|
"./sharp.node": "./lib/sharp-linuxmusl-x64.node",
|
||||||
|
"./package": "./package.json"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "^18.17.0 || ^20.3.0 || >=21.0.0"
|
||||||
|
},
|
||||||
|
"config": {
|
||||||
|
"musl": ">=1.2.2"
|
||||||
|
},
|
||||||
|
"os": [
|
||||||
|
"linux"
|
||||||
|
],
|
||||||
|
"libc": [
|
||||||
|
"musl"
|
||||||
|
],
|
||||||
|
"cpu": [
|
||||||
|
"x64"
|
||||||
|
]
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
Copyright (c) 2015, Contributors
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and/or distribute this software
|
||||||
|
for any purpose with or without fee is hereby granted, provided
|
||||||
|
that the above copyright notice and this permission notice
|
||||||
|
appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE
|
||||||
|
LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES
|
||||||
|
OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||||
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||||
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
+143
@@ -0,0 +1,143 @@
|
|||||||
|
# @isaacs/cliui
|
||||||
|
|
||||||
|
Temporary fork of [cliui](http://npm.im/cliui).
|
||||||
|
|
||||||
|

|
||||||
|
[](https://www.npmjs.com/package/cliui)
|
||||||
|
[](https://conventionalcommits.org)
|
||||||
|

|
||||||
|
|
||||||
|
easily create complex multi-column command-line-interfaces.
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```js
|
||||||
|
const ui = require('cliui')()
|
||||||
|
|
||||||
|
ui.div('Usage: $0 [command] [options]')
|
||||||
|
|
||||||
|
ui.div({
|
||||||
|
text: 'Options:',
|
||||||
|
padding: [2, 0, 1, 0]
|
||||||
|
})
|
||||||
|
|
||||||
|
ui.div(
|
||||||
|
{
|
||||||
|
text: "-f, --file",
|
||||||
|
width: 20,
|
||||||
|
padding: [0, 4, 0, 4]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: "the file to load." +
|
||||||
|
chalk.green("(if this description is long it wraps).")
|
||||||
|
,
|
||||||
|
width: 20
|
||||||
|
},
|
||||||
|
{
|
||||||
|
text: chalk.red("[required]"),
|
||||||
|
align: 'right'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log(ui.toString())
|
||||||
|
```
|
||||||
|
|
||||||
|
## Deno/ESM Support
|
||||||
|
|
||||||
|
As of `v7` `cliui` supports [Deno](https://github.com/denoland/deno) and
|
||||||
|
[ESM](https://nodejs.org/api/esm.html#esm_ecmascript_modules):
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import cliui from "https://deno.land/x/cliui/deno.ts";
|
||||||
|
|
||||||
|
const ui = cliui({})
|
||||||
|
|
||||||
|
ui.div('Usage: $0 [command] [options]')
|
||||||
|
|
||||||
|
ui.div({
|
||||||
|
text: 'Options:',
|
||||||
|
padding: [2, 0, 1, 0]
|
||||||
|
})
|
||||||
|
|
||||||
|
ui.div({
|
||||||
|
text: "-f, --file",
|
||||||
|
width: 20,
|
||||||
|
padding: [0, 4, 0, 4]
|
||||||
|
})
|
||||||
|
|
||||||
|
console.log(ui.toString())
|
||||||
|
```
|
||||||
|
|
||||||
|
<img width="500" src="screenshot.png">
|
||||||
|
|
||||||
|
## Layout DSL
|
||||||
|
|
||||||
|
cliui exposes a simple layout DSL:
|
||||||
|
|
||||||
|
If you create a single `ui.div`, passing a string rather than an
|
||||||
|
object:
|
||||||
|
|
||||||
|
* `\n`: characters will be interpreted as new rows.
|
||||||
|
* `\t`: characters will be interpreted as new columns.
|
||||||
|
* `\s`: characters will be interpreted as padding.
|
||||||
|
|
||||||
|
**as an example...**
|
||||||
|
|
||||||
|
```js
|
||||||
|
var ui = require('./')({
|
||||||
|
width: 60
|
||||||
|
})
|
||||||
|
|
||||||
|
ui.div(
|
||||||
|
'Usage: node ./bin/foo.js\n' +
|
||||||
|
' <regex>\t provide a regex\n' +
|
||||||
|
' <glob>\t provide a glob\t [required]'
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log(ui.toString())
|
||||||
|
```
|
||||||
|
|
||||||
|
**will output:**
|
||||||
|
|
||||||
|
```shell
|
||||||
|
Usage: node ./bin/foo.js
|
||||||
|
<regex> provide a regex
|
||||||
|
<glob> provide a glob [required]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Methods
|
||||||
|
|
||||||
|
```js
|
||||||
|
cliui = require('cliui')
|
||||||
|
```
|
||||||
|
|
||||||
|
### cliui({width: integer})
|
||||||
|
|
||||||
|
Specify the maximum width of the UI being generated.
|
||||||
|
If no width is provided, cliui will try to get the current window's width and use it, and if that doesn't work, width will be set to `80`.
|
||||||
|
|
||||||
|
### cliui({wrap: boolean})
|
||||||
|
|
||||||
|
Enable or disable the wrapping of text in a column.
|
||||||
|
|
||||||
|
### cliui.div(column, column, column)
|
||||||
|
|
||||||
|
Create a row with any number of columns, a column
|
||||||
|
can either be a string, or an object with the following
|
||||||
|
options:
|
||||||
|
|
||||||
|
* **text:** some text to place in the column.
|
||||||
|
* **width:** the width of a column.
|
||||||
|
* **align:** alignment, `right` or `center`.
|
||||||
|
* **padding:** `[top, right, bottom, left]`.
|
||||||
|
* **border:** should a border be placed around the div?
|
||||||
|
|
||||||
|
### cliui.span(column, column, column)
|
||||||
|
|
||||||
|
Similar to `div`, except the next row will be appended without
|
||||||
|
a new line being created.
|
||||||
|
|
||||||
|
### cliui.resetOutput()
|
||||||
|
|
||||||
|
Resets the UI elements of the current cliui instance, maintaining the values
|
||||||
|
set for `width` and `wrap`.
|
||||||
+317
@@ -0,0 +1,317 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const align = {
|
||||||
|
right: alignRight,
|
||||||
|
center: alignCenter
|
||||||
|
};
|
||||||
|
const top = 0;
|
||||||
|
const right = 1;
|
||||||
|
const bottom = 2;
|
||||||
|
const left = 3;
|
||||||
|
class UI {
|
||||||
|
constructor(opts) {
|
||||||
|
var _a;
|
||||||
|
this.width = opts.width;
|
||||||
|
/* c8 ignore start */
|
||||||
|
this.wrap = (_a = opts.wrap) !== null && _a !== void 0 ? _a : true;
|
||||||
|
/* c8 ignore stop */
|
||||||
|
this.rows = [];
|
||||||
|
}
|
||||||
|
span(...args) {
|
||||||
|
const cols = this.div(...args);
|
||||||
|
cols.span = true;
|
||||||
|
}
|
||||||
|
resetOutput() {
|
||||||
|
this.rows = [];
|
||||||
|
}
|
||||||
|
div(...args) {
|
||||||
|
if (args.length === 0) {
|
||||||
|
this.div('');
|
||||||
|
}
|
||||||
|
if (this.wrap && this.shouldApplyLayoutDSL(...args) && typeof args[0] === 'string') {
|
||||||
|
return this.applyLayoutDSL(args[0]);
|
||||||
|
}
|
||||||
|
const cols = args.map(arg => {
|
||||||
|
if (typeof arg === 'string') {
|
||||||
|
return this.colFromString(arg);
|
||||||
|
}
|
||||||
|
return arg;
|
||||||
|
});
|
||||||
|
this.rows.push(cols);
|
||||||
|
return cols;
|
||||||
|
}
|
||||||
|
shouldApplyLayoutDSL(...args) {
|
||||||
|
return args.length === 1 && typeof args[0] === 'string' &&
|
||||||
|
/[\t\n]/.test(args[0]);
|
||||||
|
}
|
||||||
|
applyLayoutDSL(str) {
|
||||||
|
const rows = str.split('\n').map(row => row.split('\t'));
|
||||||
|
let leftColumnWidth = 0;
|
||||||
|
// simple heuristic for layout, make sure the
|
||||||
|
// second column lines up along the left-hand.
|
||||||
|
// don't allow the first column to take up more
|
||||||
|
// than 50% of the screen.
|
||||||
|
rows.forEach(columns => {
|
||||||
|
if (columns.length > 1 && mixin.stringWidth(columns[0]) > leftColumnWidth) {
|
||||||
|
leftColumnWidth = Math.min(Math.floor(this.width * 0.5), mixin.stringWidth(columns[0]));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// generate a table:
|
||||||
|
// replacing ' ' with padding calculations.
|
||||||
|
// using the algorithmically generated width.
|
||||||
|
rows.forEach(columns => {
|
||||||
|
this.div(...columns.map((r, i) => {
|
||||||
|
return {
|
||||||
|
text: r.trim(),
|
||||||
|
padding: this.measurePadding(r),
|
||||||
|
width: (i === 0 && columns.length > 1) ? leftColumnWidth : undefined
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
return this.rows[this.rows.length - 1];
|
||||||
|
}
|
||||||
|
colFromString(text) {
|
||||||
|
return {
|
||||||
|
text,
|
||||||
|
padding: this.measurePadding(text)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
measurePadding(str) {
|
||||||
|
// measure padding without ansi escape codes
|
||||||
|
const noAnsi = mixin.stripAnsi(str);
|
||||||
|
return [0, noAnsi.match(/\s*$/)[0].length, 0, noAnsi.match(/^\s*/)[0].length];
|
||||||
|
}
|
||||||
|
toString() {
|
||||||
|
const lines = [];
|
||||||
|
this.rows.forEach(row => {
|
||||||
|
this.rowToString(row, lines);
|
||||||
|
});
|
||||||
|
// don't display any lines with the
|
||||||
|
// hidden flag set.
|
||||||
|
return lines
|
||||||
|
.filter(line => !line.hidden)
|
||||||
|
.map(line => line.text)
|
||||||
|
.join('\n');
|
||||||
|
}
|
||||||
|
rowToString(row, lines) {
|
||||||
|
this.rasterize(row).forEach((rrow, r) => {
|
||||||
|
let str = '';
|
||||||
|
rrow.forEach((col, c) => {
|
||||||
|
const { width } = row[c]; // the width with padding.
|
||||||
|
const wrapWidth = this.negatePadding(row[c]); // the width without padding.
|
||||||
|
let ts = col; // temporary string used during alignment/padding.
|
||||||
|
if (wrapWidth > mixin.stringWidth(col)) {
|
||||||
|
ts += ' '.repeat(wrapWidth - mixin.stringWidth(col));
|
||||||
|
}
|
||||||
|
// align the string within its column.
|
||||||
|
if (row[c].align && row[c].align !== 'left' && this.wrap) {
|
||||||
|
const fn = align[row[c].align];
|
||||||
|
ts = fn(ts, wrapWidth);
|
||||||
|
if (mixin.stringWidth(ts) < wrapWidth) {
|
||||||
|
/* c8 ignore start */
|
||||||
|
const w = width || 0;
|
||||||
|
/* c8 ignore stop */
|
||||||
|
ts += ' '.repeat(w - mixin.stringWidth(ts) - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// apply border and padding to string.
|
||||||
|
const padding = row[c].padding || [0, 0, 0, 0];
|
||||||
|
if (padding[left]) {
|
||||||
|
str += ' '.repeat(padding[left]);
|
||||||
|
}
|
||||||
|
str += addBorder(row[c], ts, '| ');
|
||||||
|
str += ts;
|
||||||
|
str += addBorder(row[c], ts, ' |');
|
||||||
|
if (padding[right]) {
|
||||||
|
str += ' '.repeat(padding[right]);
|
||||||
|
}
|
||||||
|
// if prior row is span, try to render the
|
||||||
|
// current row on the prior line.
|
||||||
|
if (r === 0 && lines.length > 0) {
|
||||||
|
str = this.renderInline(str, lines[lines.length - 1]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// remove trailing whitespace.
|
||||||
|
lines.push({
|
||||||
|
text: str.replace(/ +$/, ''),
|
||||||
|
span: row.span
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
// if the full 'source' can render in
|
||||||
|
// the target line, do so.
|
||||||
|
renderInline(source, previousLine) {
|
||||||
|
const match = source.match(/^ */);
|
||||||
|
/* c8 ignore start */
|
||||||
|
const leadingWhitespace = match ? match[0].length : 0;
|
||||||
|
/* c8 ignore stop */
|
||||||
|
const target = previousLine.text;
|
||||||
|
const targetTextWidth = mixin.stringWidth(target.trimEnd());
|
||||||
|
if (!previousLine.span) {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
// if we're not applying wrapping logic,
|
||||||
|
// just always append to the span.
|
||||||
|
if (!this.wrap) {
|
||||||
|
previousLine.hidden = true;
|
||||||
|
return target + source;
|
||||||
|
}
|
||||||
|
if (leadingWhitespace < targetTextWidth) {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
previousLine.hidden = true;
|
||||||
|
return target.trimEnd() + ' '.repeat(leadingWhitespace - targetTextWidth) + source.trimStart();
|
||||||
|
}
|
||||||
|
rasterize(row) {
|
||||||
|
const rrows = [];
|
||||||
|
const widths = this.columnWidths(row);
|
||||||
|
let wrapped;
|
||||||
|
// word wrap all columns, and create
|
||||||
|
// a data-structure that is easy to rasterize.
|
||||||
|
row.forEach((col, c) => {
|
||||||
|
// leave room for left and right padding.
|
||||||
|
col.width = widths[c];
|
||||||
|
if (this.wrap) {
|
||||||
|
wrapped = mixin.wrap(col.text, this.negatePadding(col), { hard: true }).split('\n');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wrapped = col.text.split('\n');
|
||||||
|
}
|
||||||
|
if (col.border) {
|
||||||
|
wrapped.unshift('.' + '-'.repeat(this.negatePadding(col) + 2) + '.');
|
||||||
|
wrapped.push("'" + '-'.repeat(this.negatePadding(col) + 2) + "'");
|
||||||
|
}
|
||||||
|
// add top and bottom padding.
|
||||||
|
if (col.padding) {
|
||||||
|
wrapped.unshift(...new Array(col.padding[top] || 0).fill(''));
|
||||||
|
wrapped.push(...new Array(col.padding[bottom] || 0).fill(''));
|
||||||
|
}
|
||||||
|
wrapped.forEach((str, r) => {
|
||||||
|
if (!rrows[r]) {
|
||||||
|
rrows.push([]);
|
||||||
|
}
|
||||||
|
const rrow = rrows[r];
|
||||||
|
for (let i = 0; i < c; i++) {
|
||||||
|
if (rrow[i] === undefined) {
|
||||||
|
rrow.push('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rrow.push(str);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return rrows;
|
||||||
|
}
|
||||||
|
negatePadding(col) {
|
||||||
|
/* c8 ignore start */
|
||||||
|
let wrapWidth = col.width || 0;
|
||||||
|
/* c8 ignore stop */
|
||||||
|
if (col.padding) {
|
||||||
|
wrapWidth -= (col.padding[left] || 0) + (col.padding[right] || 0);
|
||||||
|
}
|
||||||
|
if (col.border) {
|
||||||
|
wrapWidth -= 4;
|
||||||
|
}
|
||||||
|
return wrapWidth;
|
||||||
|
}
|
||||||
|
columnWidths(row) {
|
||||||
|
if (!this.wrap) {
|
||||||
|
return row.map(col => {
|
||||||
|
return col.width || mixin.stringWidth(col.text);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let unset = row.length;
|
||||||
|
let remainingWidth = this.width;
|
||||||
|
// column widths can be set in config.
|
||||||
|
const widths = row.map(col => {
|
||||||
|
if (col.width) {
|
||||||
|
unset--;
|
||||||
|
remainingWidth -= col.width;
|
||||||
|
return col.width;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
|
// any unset widths should be calculated.
|
||||||
|
/* c8 ignore start */
|
||||||
|
const unsetWidth = unset ? Math.floor(remainingWidth / unset) : 0;
|
||||||
|
/* c8 ignore stop */
|
||||||
|
return widths.map((w, i) => {
|
||||||
|
if (w === undefined) {
|
||||||
|
return Math.max(unsetWidth, _minWidth(row[i]));
|
||||||
|
}
|
||||||
|
return w;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function addBorder(col, ts, style) {
|
||||||
|
if (col.border) {
|
||||||
|
if (/[.']-+[.']/.test(ts)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
if (ts.trim().length !== 0) {
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
return ' ';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
// calculates the minimum width of
|
||||||
|
// a column, based on padding preferences.
|
||||||
|
function _minWidth(col) {
|
||||||
|
const padding = col.padding || [];
|
||||||
|
const minWidth = 1 + (padding[left] || 0) + (padding[right] || 0);
|
||||||
|
if (col.border) {
|
||||||
|
return minWidth + 4;
|
||||||
|
}
|
||||||
|
return minWidth;
|
||||||
|
}
|
||||||
|
function getWindowWidth() {
|
||||||
|
/* c8 ignore start */
|
||||||
|
if (typeof process === 'object' && process.stdout && process.stdout.columns) {
|
||||||
|
return process.stdout.columns;
|
||||||
|
}
|
||||||
|
return 80;
|
||||||
|
}
|
||||||
|
/* c8 ignore stop */
|
||||||
|
function alignRight(str, width) {
|
||||||
|
str = str.trim();
|
||||||
|
const strWidth = mixin.stringWidth(str);
|
||||||
|
if (strWidth < width) {
|
||||||
|
return ' '.repeat(width - strWidth) + str;
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
function alignCenter(str, width) {
|
||||||
|
str = str.trim();
|
||||||
|
const strWidth = mixin.stringWidth(str);
|
||||||
|
/* c8 ignore start */
|
||||||
|
if (strWidth >= width) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
/* c8 ignore stop */
|
||||||
|
return ' '.repeat((width - strWidth) >> 1) + str;
|
||||||
|
}
|
||||||
|
let mixin;
|
||||||
|
function cliui(opts, _mixin) {
|
||||||
|
mixin = _mixin;
|
||||||
|
return new UI({
|
||||||
|
/* c8 ignore start */
|
||||||
|
width: (opts === null || opts === void 0 ? void 0 : opts.width) || getWindowWidth(),
|
||||||
|
wrap: opts === null || opts === void 0 ? void 0 : opts.wrap
|
||||||
|
/* c8 ignore stop */
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bootstrap cliui with CommonJS dependencies:
|
||||||
|
const stringWidth = require('string-width-cjs');
|
||||||
|
const stripAnsi = require('strip-ansi-cjs');
|
||||||
|
const wrap = require('wrap-ansi-cjs');
|
||||||
|
function ui(opts) {
|
||||||
|
return cliui(opts, {
|
||||||
|
stringWidth,
|
||||||
|
stripAnsi,
|
||||||
|
wrap
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = ui;
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
interface UIOptions {
|
||||||
|
width: number;
|
||||||
|
wrap?: boolean;
|
||||||
|
rows?: string[];
|
||||||
|
}
|
||||||
|
interface Column {
|
||||||
|
text: string;
|
||||||
|
width?: number;
|
||||||
|
align?: "right" | "left" | "center";
|
||||||
|
padding: number[];
|
||||||
|
border?: boolean;
|
||||||
|
}
|
||||||
|
interface ColumnArray extends Array<Column> {
|
||||||
|
span: boolean;
|
||||||
|
}
|
||||||
|
interface Line {
|
||||||
|
hidden?: boolean;
|
||||||
|
text: string;
|
||||||
|
span?: boolean;
|
||||||
|
}
|
||||||
|
declare class UI {
|
||||||
|
width: number;
|
||||||
|
wrap: boolean;
|
||||||
|
rows: ColumnArray[];
|
||||||
|
constructor(opts: UIOptions);
|
||||||
|
span(...args: ColumnArray): void;
|
||||||
|
resetOutput(): void;
|
||||||
|
div(...args: (Column | string)[]): ColumnArray;
|
||||||
|
private shouldApplyLayoutDSL;
|
||||||
|
private applyLayoutDSL;
|
||||||
|
private colFromString;
|
||||||
|
private measurePadding;
|
||||||
|
toString(): string;
|
||||||
|
rowToString(row: ColumnArray, lines: Line[]): Line[];
|
||||||
|
// if the full 'source' can render in
|
||||||
|
// the target line, do so.
|
||||||
|
private renderInline;
|
||||||
|
private rasterize;
|
||||||
|
private negatePadding;
|
||||||
|
private columnWidths;
|
||||||
|
}
|
||||||
|
declare function ui(opts: UIOptions): UI;
|
||||||
|
export { ui as default };
|
||||||
+302
@@ -0,0 +1,302 @@
|
|||||||
|
'use strict';
|
||||||
|
const align = {
|
||||||
|
right: alignRight,
|
||||||
|
center: alignCenter
|
||||||
|
};
|
||||||
|
const top = 0;
|
||||||
|
const right = 1;
|
||||||
|
const bottom = 2;
|
||||||
|
const left = 3;
|
||||||
|
export class UI {
|
||||||
|
constructor(opts) {
|
||||||
|
var _a;
|
||||||
|
this.width = opts.width;
|
||||||
|
/* c8 ignore start */
|
||||||
|
this.wrap = (_a = opts.wrap) !== null && _a !== void 0 ? _a : true;
|
||||||
|
/* c8 ignore stop */
|
||||||
|
this.rows = [];
|
||||||
|
}
|
||||||
|
span(...args) {
|
||||||
|
const cols = this.div(...args);
|
||||||
|
cols.span = true;
|
||||||
|
}
|
||||||
|
resetOutput() {
|
||||||
|
this.rows = [];
|
||||||
|
}
|
||||||
|
div(...args) {
|
||||||
|
if (args.length === 0) {
|
||||||
|
this.div('');
|
||||||
|
}
|
||||||
|
if (this.wrap && this.shouldApplyLayoutDSL(...args) && typeof args[0] === 'string') {
|
||||||
|
return this.applyLayoutDSL(args[0]);
|
||||||
|
}
|
||||||
|
const cols = args.map(arg => {
|
||||||
|
if (typeof arg === 'string') {
|
||||||
|
return this.colFromString(arg);
|
||||||
|
}
|
||||||
|
return arg;
|
||||||
|
});
|
||||||
|
this.rows.push(cols);
|
||||||
|
return cols;
|
||||||
|
}
|
||||||
|
shouldApplyLayoutDSL(...args) {
|
||||||
|
return args.length === 1 && typeof args[0] === 'string' &&
|
||||||
|
/[\t\n]/.test(args[0]);
|
||||||
|
}
|
||||||
|
applyLayoutDSL(str) {
|
||||||
|
const rows = str.split('\n').map(row => row.split('\t'));
|
||||||
|
let leftColumnWidth = 0;
|
||||||
|
// simple heuristic for layout, make sure the
|
||||||
|
// second column lines up along the left-hand.
|
||||||
|
// don't allow the first column to take up more
|
||||||
|
// than 50% of the screen.
|
||||||
|
rows.forEach(columns => {
|
||||||
|
if (columns.length > 1 && mixin.stringWidth(columns[0]) > leftColumnWidth) {
|
||||||
|
leftColumnWidth = Math.min(Math.floor(this.width * 0.5), mixin.stringWidth(columns[0]));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// generate a table:
|
||||||
|
// replacing ' ' with padding calculations.
|
||||||
|
// using the algorithmically generated width.
|
||||||
|
rows.forEach(columns => {
|
||||||
|
this.div(...columns.map((r, i) => {
|
||||||
|
return {
|
||||||
|
text: r.trim(),
|
||||||
|
padding: this.measurePadding(r),
|
||||||
|
width: (i === 0 && columns.length > 1) ? leftColumnWidth : undefined
|
||||||
|
};
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
return this.rows[this.rows.length - 1];
|
||||||
|
}
|
||||||
|
colFromString(text) {
|
||||||
|
return {
|
||||||
|
text,
|
||||||
|
padding: this.measurePadding(text)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
measurePadding(str) {
|
||||||
|
// measure padding without ansi escape codes
|
||||||
|
const noAnsi = mixin.stripAnsi(str);
|
||||||
|
return [0, noAnsi.match(/\s*$/)[0].length, 0, noAnsi.match(/^\s*/)[0].length];
|
||||||
|
}
|
||||||
|
toString() {
|
||||||
|
const lines = [];
|
||||||
|
this.rows.forEach(row => {
|
||||||
|
this.rowToString(row, lines);
|
||||||
|
});
|
||||||
|
// don't display any lines with the
|
||||||
|
// hidden flag set.
|
||||||
|
return lines
|
||||||
|
.filter(line => !line.hidden)
|
||||||
|
.map(line => line.text)
|
||||||
|
.join('\n');
|
||||||
|
}
|
||||||
|
rowToString(row, lines) {
|
||||||
|
this.rasterize(row).forEach((rrow, r) => {
|
||||||
|
let str = '';
|
||||||
|
rrow.forEach((col, c) => {
|
||||||
|
const { width } = row[c]; // the width with padding.
|
||||||
|
const wrapWidth = this.negatePadding(row[c]); // the width without padding.
|
||||||
|
let ts = col; // temporary string used during alignment/padding.
|
||||||
|
if (wrapWidth > mixin.stringWidth(col)) {
|
||||||
|
ts += ' '.repeat(wrapWidth - mixin.stringWidth(col));
|
||||||
|
}
|
||||||
|
// align the string within its column.
|
||||||
|
if (row[c].align && row[c].align !== 'left' && this.wrap) {
|
||||||
|
const fn = align[row[c].align];
|
||||||
|
ts = fn(ts, wrapWidth);
|
||||||
|
if (mixin.stringWidth(ts) < wrapWidth) {
|
||||||
|
/* c8 ignore start */
|
||||||
|
const w = width || 0;
|
||||||
|
/* c8 ignore stop */
|
||||||
|
ts += ' '.repeat(w - mixin.stringWidth(ts) - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// apply border and padding to string.
|
||||||
|
const padding = row[c].padding || [0, 0, 0, 0];
|
||||||
|
if (padding[left]) {
|
||||||
|
str += ' '.repeat(padding[left]);
|
||||||
|
}
|
||||||
|
str += addBorder(row[c], ts, '| ');
|
||||||
|
str += ts;
|
||||||
|
str += addBorder(row[c], ts, ' |');
|
||||||
|
if (padding[right]) {
|
||||||
|
str += ' '.repeat(padding[right]);
|
||||||
|
}
|
||||||
|
// if prior row is span, try to render the
|
||||||
|
// current row on the prior line.
|
||||||
|
if (r === 0 && lines.length > 0) {
|
||||||
|
str = this.renderInline(str, lines[lines.length - 1]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// remove trailing whitespace.
|
||||||
|
lines.push({
|
||||||
|
text: str.replace(/ +$/, ''),
|
||||||
|
span: row.span
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return lines;
|
||||||
|
}
|
||||||
|
// if the full 'source' can render in
|
||||||
|
// the target line, do so.
|
||||||
|
renderInline(source, previousLine) {
|
||||||
|
const match = source.match(/^ */);
|
||||||
|
/* c8 ignore start */
|
||||||
|
const leadingWhitespace = match ? match[0].length : 0;
|
||||||
|
/* c8 ignore stop */
|
||||||
|
const target = previousLine.text;
|
||||||
|
const targetTextWidth = mixin.stringWidth(target.trimEnd());
|
||||||
|
if (!previousLine.span) {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
// if we're not applying wrapping logic,
|
||||||
|
// just always append to the span.
|
||||||
|
if (!this.wrap) {
|
||||||
|
previousLine.hidden = true;
|
||||||
|
return target + source;
|
||||||
|
}
|
||||||
|
if (leadingWhitespace < targetTextWidth) {
|
||||||
|
return source;
|
||||||
|
}
|
||||||
|
previousLine.hidden = true;
|
||||||
|
return target.trimEnd() + ' '.repeat(leadingWhitespace - targetTextWidth) + source.trimStart();
|
||||||
|
}
|
||||||
|
rasterize(row) {
|
||||||
|
const rrows = [];
|
||||||
|
const widths = this.columnWidths(row);
|
||||||
|
let wrapped;
|
||||||
|
// word wrap all columns, and create
|
||||||
|
// a data-structure that is easy to rasterize.
|
||||||
|
row.forEach((col, c) => {
|
||||||
|
// leave room for left and right padding.
|
||||||
|
col.width = widths[c];
|
||||||
|
if (this.wrap) {
|
||||||
|
wrapped = mixin.wrap(col.text, this.negatePadding(col), { hard: true }).split('\n');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
wrapped = col.text.split('\n');
|
||||||
|
}
|
||||||
|
if (col.border) {
|
||||||
|
wrapped.unshift('.' + '-'.repeat(this.negatePadding(col) + 2) + '.');
|
||||||
|
wrapped.push("'" + '-'.repeat(this.negatePadding(col) + 2) + "'");
|
||||||
|
}
|
||||||
|
// add top and bottom padding.
|
||||||
|
if (col.padding) {
|
||||||
|
wrapped.unshift(...new Array(col.padding[top] || 0).fill(''));
|
||||||
|
wrapped.push(...new Array(col.padding[bottom] || 0).fill(''));
|
||||||
|
}
|
||||||
|
wrapped.forEach((str, r) => {
|
||||||
|
if (!rrows[r]) {
|
||||||
|
rrows.push([]);
|
||||||
|
}
|
||||||
|
const rrow = rrows[r];
|
||||||
|
for (let i = 0; i < c; i++) {
|
||||||
|
if (rrow[i] === undefined) {
|
||||||
|
rrow.push('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rrow.push(str);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return rrows;
|
||||||
|
}
|
||||||
|
negatePadding(col) {
|
||||||
|
/* c8 ignore start */
|
||||||
|
let wrapWidth = col.width || 0;
|
||||||
|
/* c8 ignore stop */
|
||||||
|
if (col.padding) {
|
||||||
|
wrapWidth -= (col.padding[left] || 0) + (col.padding[right] || 0);
|
||||||
|
}
|
||||||
|
if (col.border) {
|
||||||
|
wrapWidth -= 4;
|
||||||
|
}
|
||||||
|
return wrapWidth;
|
||||||
|
}
|
||||||
|
columnWidths(row) {
|
||||||
|
if (!this.wrap) {
|
||||||
|
return row.map(col => {
|
||||||
|
return col.width || mixin.stringWidth(col.text);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let unset = row.length;
|
||||||
|
let remainingWidth = this.width;
|
||||||
|
// column widths can be set in config.
|
||||||
|
const widths = row.map(col => {
|
||||||
|
if (col.width) {
|
||||||
|
unset--;
|
||||||
|
remainingWidth -= col.width;
|
||||||
|
return col.width;
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
|
// any unset widths should be calculated.
|
||||||
|
/* c8 ignore start */
|
||||||
|
const unsetWidth = unset ? Math.floor(remainingWidth / unset) : 0;
|
||||||
|
/* c8 ignore stop */
|
||||||
|
return widths.map((w, i) => {
|
||||||
|
if (w === undefined) {
|
||||||
|
return Math.max(unsetWidth, _minWidth(row[i]));
|
||||||
|
}
|
||||||
|
return w;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function addBorder(col, ts, style) {
|
||||||
|
if (col.border) {
|
||||||
|
if (/[.']-+[.']/.test(ts)) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
if (ts.trim().length !== 0) {
|
||||||
|
return style;
|
||||||
|
}
|
||||||
|
return ' ';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
// calculates the minimum width of
|
||||||
|
// a column, based on padding preferences.
|
||||||
|
function _minWidth(col) {
|
||||||
|
const padding = col.padding || [];
|
||||||
|
const minWidth = 1 + (padding[left] || 0) + (padding[right] || 0);
|
||||||
|
if (col.border) {
|
||||||
|
return minWidth + 4;
|
||||||
|
}
|
||||||
|
return minWidth;
|
||||||
|
}
|
||||||
|
function getWindowWidth() {
|
||||||
|
/* c8 ignore start */
|
||||||
|
if (typeof process === 'object' && process.stdout && process.stdout.columns) {
|
||||||
|
return process.stdout.columns;
|
||||||
|
}
|
||||||
|
return 80;
|
||||||
|
}
|
||||||
|
/* c8 ignore stop */
|
||||||
|
function alignRight(str, width) {
|
||||||
|
str = str.trim();
|
||||||
|
const strWidth = mixin.stringWidth(str);
|
||||||
|
if (strWidth < width) {
|
||||||
|
return ' '.repeat(width - strWidth) + str;
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
function alignCenter(str, width) {
|
||||||
|
str = str.trim();
|
||||||
|
const strWidth = mixin.stringWidth(str);
|
||||||
|
/* c8 ignore start */
|
||||||
|
if (strWidth >= width) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
/* c8 ignore stop */
|
||||||
|
return ' '.repeat((width - strWidth) >> 1) + str;
|
||||||
|
}
|
||||||
|
let mixin;
|
||||||
|
export function cliui(opts, _mixin) {
|
||||||
|
mixin = _mixin;
|
||||||
|
return new UI({
|
||||||
|
/* c8 ignore start */
|
||||||
|
width: (opts === null || opts === void 0 ? void 0 : opts.width) || getWindowWidth(),
|
||||||
|
wrap: opts === null || opts === void 0 ? void 0 : opts.wrap
|
||||||
|
/* c8 ignore stop */
|
||||||
|
});
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
// Bootstrap cliui with ESM dependencies:
|
||||||
|
import { cliui } from './build/lib/index.js'
|
||||||
|
|
||||||
|
import stringWidth from 'string-width'
|
||||||
|
import stripAnsi from 'strip-ansi'
|
||||||
|
import wrap from 'wrap-ansi'
|
||||||
|
|
||||||
|
export default function ui (opts) {
|
||||||
|
return cliui(opts, {
|
||||||
|
stringWidth,
|
||||||
|
stripAnsi,
|
||||||
|
wrap
|
||||||
|
})
|
||||||
|
}
|
||||||
+86
@@ -0,0 +1,86 @@
|
|||||||
|
{
|
||||||
|
"name": "@isaacs/cliui",
|
||||||
|
"version": "8.0.2",
|
||||||
|
"description": "easily create complex multi-column command-line-interfaces",
|
||||||
|
"main": "build/index.cjs",
|
||||||
|
"exports": {
|
||||||
|
".": [
|
||||||
|
{
|
||||||
|
"import": "./index.mjs",
|
||||||
|
"require": "./build/index.cjs"
|
||||||
|
},
|
||||||
|
"./build/index.cjs"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"type": "module",
|
||||||
|
"module": "./index.mjs",
|
||||||
|
"scripts": {
|
||||||
|
"check": "standardx '**/*.ts' && standardx '**/*.js' && standardx '**/*.cjs'",
|
||||||
|
"fix": "standardx --fix '**/*.ts' && standardx --fix '**/*.js' && standardx --fix '**/*.cjs'",
|
||||||
|
"pretest": "rimraf build && tsc -p tsconfig.test.json && cross-env NODE_ENV=test npm run build:cjs",
|
||||||
|
"test": "c8 mocha ./test/*.cjs",
|
||||||
|
"test:esm": "c8 mocha ./test/**/*.mjs",
|
||||||
|
"postest": "check",
|
||||||
|
"coverage": "c8 report --check-coverage",
|
||||||
|
"precompile": "rimraf build",
|
||||||
|
"compile": "tsc",
|
||||||
|
"postcompile": "npm run build:cjs",
|
||||||
|
"build:cjs": "rollup -c",
|
||||||
|
"prepare": "npm run compile"
|
||||||
|
},
|
||||||
|
"repository": "yargs/cliui",
|
||||||
|
"standard": {
|
||||||
|
"ignore": [
|
||||||
|
"**/example/**"
|
||||||
|
],
|
||||||
|
"globals": [
|
||||||
|
"it"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"cli",
|
||||||
|
"command-line",
|
||||||
|
"layout",
|
||||||
|
"design",
|
||||||
|
"console",
|
||||||
|
"wrap",
|
||||||
|
"table"
|
||||||
|
],
|
||||||
|
"author": "Ben Coe <ben@npmjs.com>",
|
||||||
|
"license": "ISC",
|
||||||
|
"dependencies": {
|
||||||
|
"string-width": "^5.1.2",
|
||||||
|
"string-width-cjs": "npm:string-width@^4.2.0",
|
||||||
|
"strip-ansi": "^7.0.1",
|
||||||
|
"strip-ansi-cjs": "npm:strip-ansi@^6.0.1",
|
||||||
|
"wrap-ansi": "^8.1.0",
|
||||||
|
"wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^14.0.27",
|
||||||
|
"@typescript-eslint/eslint-plugin": "^4.0.0",
|
||||||
|
"@typescript-eslint/parser": "^4.0.0",
|
||||||
|
"c8": "^7.3.0",
|
||||||
|
"chai": "^4.2.0",
|
||||||
|
"chalk": "^4.1.0",
|
||||||
|
"cross-env": "^7.0.2",
|
||||||
|
"eslint": "^7.6.0",
|
||||||
|
"eslint-plugin-import": "^2.22.0",
|
||||||
|
"eslint-plugin-node": "^11.1.0",
|
||||||
|
"gts": "^3.0.0",
|
||||||
|
"mocha": "^10.0.0",
|
||||||
|
"rimraf": "^3.0.2",
|
||||||
|
"rollup": "^2.23.1",
|
||||||
|
"rollup-plugin-ts": "^3.0.2",
|
||||||
|
"standardx": "^7.0.0",
|
||||||
|
"typescript": "^4.0.0"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"build",
|
||||||
|
"index.mjs",
|
||||||
|
"!*.d.ts"
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
# EditorConfig is awesome: http://EditorConfig.org
|
||||||
|
|
||||||
|
# top-most EditorConfig file
|
||||||
|
root = true
|
||||||
|
|
||||||
|
# Copied from Node.js to ease compatibility in PR.
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_size = 2
|
||||||
|
indent_style = space
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
quote_type = single
|
||||||
+147
@@ -0,0 +1,147 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## [0.11.0](https://github.com/pkgjs/parseargs/compare/v0.10.0...v0.11.0) (2022-10-08)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add `default` option parameter ([#142](https://github.com/pkgjs/parseargs/issues/142)) ([cd20847](https://github.com/pkgjs/parseargs/commit/cd20847a00b2f556aa9c085ac83b942c60868ec1))
|
||||||
|
|
||||||
|
## [0.10.0](https://github.com/pkgjs/parseargs/compare/v0.9.1...v0.10.0) (2022-07-21)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add parsed meta-data to returned properties ([#129](https://github.com/pkgjs/parseargs/issues/129)) ([91bfb4d](https://github.com/pkgjs/parseargs/commit/91bfb4d3f7b6937efab1b27c91c45d1205f1497e))
|
||||||
|
|
||||||
|
## [0.9.1](https://github.com/pkgjs/parseargs/compare/v0.9.0...v0.9.1) (2022-06-20)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* **runtime:** support node 14+ ([#135](https://github.com/pkgjs/parseargs/issues/135)) ([6a1c5a6](https://github.com/pkgjs/parseargs/commit/6a1c5a6f7cadf2f035e004027e2742e3c4ce554b))
|
||||||
|
|
||||||
|
## [0.9.0](https://github.com/pkgjs/parseargs/compare/v0.8.0...v0.9.0) (2022-05-23)
|
||||||
|
|
||||||
|
|
||||||
|
### ⚠ BREAKING CHANGES
|
||||||
|
|
||||||
|
* drop handling of electron arguments (#121)
|
||||||
|
|
||||||
|
### Code Refactoring
|
||||||
|
|
||||||
|
* drop handling of electron arguments ([#121](https://github.com/pkgjs/parseargs/issues/121)) ([a2ffd53](https://github.com/pkgjs/parseargs/commit/a2ffd537c244a062371522b955acb45a404fc9f2))
|
||||||
|
|
||||||
|
## [0.8.0](https://github.com/pkgjs/parseargs/compare/v0.7.1...v0.8.0) (2022-05-16)
|
||||||
|
|
||||||
|
|
||||||
|
### ⚠ BREAKING CHANGES
|
||||||
|
|
||||||
|
* switch type:string option arguments to greedy, but with error for suspect cases in strict mode (#88)
|
||||||
|
* positionals now opt-in when strict:true (#116)
|
||||||
|
* create result.values with null prototype (#111)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* create result.values with null prototype ([#111](https://github.com/pkgjs/parseargs/issues/111)) ([9d539c3](https://github.com/pkgjs/parseargs/commit/9d539c3d57f269c160e74e0656ad4fa84ff92ec2))
|
||||||
|
* positionals now opt-in when strict:true ([#116](https://github.com/pkgjs/parseargs/issues/116)) ([3643338](https://github.com/pkgjs/parseargs/commit/364333826b746e8a7dc5505b4b22fd19ac51df3b))
|
||||||
|
* switch type:string option arguments to greedy, but with error for suspect cases in strict mode ([#88](https://github.com/pkgjs/parseargs/issues/88)) ([c2b5e72](https://github.com/pkgjs/parseargs/commit/c2b5e72161991dfdc535909f1327cc9b970fe7e8))
|
||||||
|
|
||||||
|
### [0.7.1](https://github.com/pkgjs/parseargs/compare/v0.7.0...v0.7.1) (2022-04-15)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* resist pollution ([#106](https://github.com/pkgjs/parseargs/issues/106)) ([ecf2dec](https://github.com/pkgjs/parseargs/commit/ecf2dece0a9f2a76d789384d5d71c68ffe64022a))
|
||||||
|
|
||||||
|
## [0.7.0](https://github.com/pkgjs/parseargs/compare/v0.6.0...v0.7.0) (2022-04-13)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Add strict mode to parser ([#74](https://github.com/pkgjs/parseargs/issues/74)) ([8267d02](https://github.com/pkgjs/parseargs/commit/8267d02083a87b8b8a71fcce08348d1e031ea91c))
|
||||||
|
|
||||||
|
## [0.6.0](https://github.com/pkgjs/parseargs/compare/v0.5.0...v0.6.0) (2022-04-11)
|
||||||
|
|
||||||
|
|
||||||
|
### ⚠ BREAKING CHANGES
|
||||||
|
|
||||||
|
* rework results to remove redundant `flags` property and store value true for boolean options (#83)
|
||||||
|
* switch to existing ERR_INVALID_ARG_VALUE (#97)
|
||||||
|
|
||||||
|
### Code Refactoring
|
||||||
|
|
||||||
|
* rework results to remove redundant `flags` property and store value true for boolean options ([#83](https://github.com/pkgjs/parseargs/issues/83)) ([be153db](https://github.com/pkgjs/parseargs/commit/be153dbed1d488cb7b6e27df92f601ba7337713d))
|
||||||
|
* switch to existing ERR_INVALID_ARG_VALUE ([#97](https://github.com/pkgjs/parseargs/issues/97)) ([084a23f](https://github.com/pkgjs/parseargs/commit/084a23f9fde2da030b159edb1c2385f24579ce40))
|
||||||
|
|
||||||
|
## [0.5.0](https://github.com/pkgjs/parseargs/compare/v0.4.0...v0.5.0) (2022-04-10)
|
||||||
|
|
||||||
|
|
||||||
|
### ⚠ BREAKING CHANGES
|
||||||
|
|
||||||
|
* Require type to be specified for each supplied option (#95)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* Require type to be specified for each supplied option ([#95](https://github.com/pkgjs/parseargs/issues/95)) ([02cd018](https://github.com/pkgjs/parseargs/commit/02cd01885b8aaa59f2db8308f2d4479e64340068))
|
||||||
|
|
||||||
|
## [0.4.0](https://github.com/pkgjs/parseargs/compare/v0.3.0...v0.4.0) (2022-03-12)
|
||||||
|
|
||||||
|
|
||||||
|
### ⚠ BREAKING CHANGES
|
||||||
|
|
||||||
|
* parsing, revisit short option groups, add support for combined short and value (#75)
|
||||||
|
* restructure configuration to take options bag (#63)
|
||||||
|
|
||||||
|
### Code Refactoring
|
||||||
|
|
||||||
|
* parsing, revisit short option groups, add support for combined short and value ([#75](https://github.com/pkgjs/parseargs/issues/75)) ([a92600f](https://github.com/pkgjs/parseargs/commit/a92600fa6c214508ab1e016fa55879a314f541af))
|
||||||
|
* restructure configuration to take options bag ([#63](https://github.com/pkgjs/parseargs/issues/63)) ([b412095](https://github.com/pkgjs/parseargs/commit/b4120957d90e809ee8b607b06e747d3e6a6b213e))
|
||||||
|
|
||||||
|
## [0.3.0](https://github.com/pkgjs/parseargs/compare/v0.2.0...v0.3.0) (2022-02-06)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* **parser:** support short-option groups ([#59](https://github.com/pkgjs/parseargs/issues/59)) ([882067b](https://github.com/pkgjs/parseargs/commit/882067bc2d7cbc6b796f8e5a079a99bc99d4e6ba))
|
||||||
|
|
||||||
|
## [0.2.0](https://github.com/pkgjs/parseargs/compare/v0.1.1...v0.2.0) (2022-02-05)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* basic support for shorts ([#50](https://github.com/pkgjs/parseargs/issues/50)) ([a2f36d7](https://github.com/pkgjs/parseargs/commit/a2f36d7da4145af1c92f76806b7fe2baf6beeceb))
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* always store value for a=b ([#43](https://github.com/pkgjs/parseargs/issues/43)) ([a85e8dc](https://github.com/pkgjs/parseargs/commit/a85e8dc06379fd2696ee195cc625de8fac6aee42))
|
||||||
|
* support single dash as positional ([#49](https://github.com/pkgjs/parseargs/issues/49)) ([d795bf8](https://github.com/pkgjs/parseargs/commit/d795bf877d068fd67aec381f30b30b63f97109ad))
|
||||||
|
|
||||||
|
### [0.1.1](https://github.com/pkgjs/parseargs/compare/v0.1.0...v0.1.1) (2022-01-25)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* only use arrays in results for multiples ([#42](https://github.com/pkgjs/parseargs/issues/42)) ([c357584](https://github.com/pkgjs/parseargs/commit/c357584847912506319ed34a0840080116f4fd65))
|
||||||
|
|
||||||
|
## 0.1.0 (2022-01-22)
|
||||||
|
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* expand scenarios covered by default arguments for environments ([#20](https://github.com/pkgjs/parseargs/issues/20)) ([582ada7](https://github.com/pkgjs/parseargs/commit/582ada7be0eca3a73d6e0bd016e7ace43449fa4c))
|
||||||
|
* update readme and include contributing guidelines ([8edd6fc](https://github.com/pkgjs/parseargs/commit/8edd6fc863cd705f6fac732724159ebe8065a2b0))
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* do not strip excess leading dashes on long option names ([#21](https://github.com/pkgjs/parseargs/issues/21)) ([f848590](https://github.com/pkgjs/parseargs/commit/f848590ebf3249ed5979ff47e003fa6e1a8ec5c0))
|
||||||
|
* name & readme ([3f057c1](https://github.com/pkgjs/parseargs/commit/3f057c1b158a1bdbe878c64b57460c58e56e465f))
|
||||||
|
* package.json values ([9bac300](https://github.com/pkgjs/parseargs/commit/9bac300e00cd76c77076bf9e75e44f8929512da9))
|
||||||
|
* update readme name ([957d8d9](https://github.com/pkgjs/parseargs/commit/957d8d96e1dcb48297c0a14345d44c0123b2883e))
|
||||||
|
|
||||||
|
|
||||||
|
### Build System
|
||||||
|
|
||||||
|
* first release as minor ([421c6e2](https://github.com/pkgjs/parseargs/commit/421c6e2569a8668ad14fac5a5af5be60479a7571))
|
||||||
+201
@@ -0,0 +1,201 @@
|
|||||||
|
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
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
+413
@@ -0,0 +1,413 @@
|
|||||||
|
<!-- omit in toc -->
|
||||||
|
# parseArgs
|
||||||
|
|
||||||
|
[![Coverage][coverage-image]][coverage-url]
|
||||||
|
|
||||||
|
Polyfill of `util.parseArgs()`
|
||||||
|
|
||||||
|
## `util.parseArgs([config])`
|
||||||
|
|
||||||
|
<!-- YAML
|
||||||
|
added: v18.3.0
|
||||||
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/43459
|
||||||
|
description: add support for returning detailed parse information
|
||||||
|
using `tokens` in input `config` and returned properties.
|
||||||
|
-->
|
||||||
|
|
||||||
|
> Stability: 1 - Experimental
|
||||||
|
|
||||||
|
* `config` {Object} Used to provide arguments for parsing and to configure
|
||||||
|
the parser. `config` supports the following properties:
|
||||||
|
* `args` {string\[]} array of argument strings. **Default:** `process.argv`
|
||||||
|
with `execPath` and `filename` removed.
|
||||||
|
* `options` {Object} Used to describe arguments known to the parser.
|
||||||
|
Keys of `options` are the long names of options and values are an
|
||||||
|
{Object} accepting the following properties:
|
||||||
|
* `type` {string} Type of argument, which must be either `boolean` or `string`.
|
||||||
|
* `multiple` {boolean} Whether this option can be provided multiple
|
||||||
|
times. If `true`, all values will be collected in an array. If
|
||||||
|
`false`, values for the option are last-wins. **Default:** `false`.
|
||||||
|
* `short` {string} A single character alias for the option.
|
||||||
|
* `default` {string | boolean | string\[] | boolean\[]} The default option
|
||||||
|
value when it is not set by args. It must be of the same type as the
|
||||||
|
the `type` property. When `multiple` is `true`, it must be an array.
|
||||||
|
* `strict` {boolean} Should an error be thrown when unknown arguments
|
||||||
|
are encountered, or when arguments are passed that do not match the
|
||||||
|
`type` configured in `options`.
|
||||||
|
**Default:** `true`.
|
||||||
|
* `allowPositionals` {boolean} Whether this command accepts positional
|
||||||
|
arguments.
|
||||||
|
**Default:** `false` if `strict` is `true`, otherwise `true`.
|
||||||
|
* `tokens` {boolean} Return the parsed tokens. This is useful for extending
|
||||||
|
the built-in behavior, from adding additional checks through to reprocessing
|
||||||
|
the tokens in different ways.
|
||||||
|
**Default:** `false`.
|
||||||
|
|
||||||
|
* Returns: {Object} The parsed command line arguments:
|
||||||
|
* `values` {Object} A mapping of parsed option names with their {string}
|
||||||
|
or {boolean} values.
|
||||||
|
* `positionals` {string\[]} Positional arguments.
|
||||||
|
* `tokens` {Object\[] | undefined} See [parseArgs tokens](#parseargs-tokens)
|
||||||
|
section. Only returned if `config` includes `tokens: true`.
|
||||||
|
|
||||||
|
Provides a higher level API for command-line argument parsing than interacting
|
||||||
|
with `process.argv` directly. Takes a specification for the expected arguments
|
||||||
|
and returns a structured object with the parsed options and positionals.
|
||||||
|
|
||||||
|
```mjs
|
||||||
|
import { parseArgs } from 'node:util';
|
||||||
|
const args = ['-f', '--bar', 'b'];
|
||||||
|
const options = {
|
||||||
|
foo: {
|
||||||
|
type: 'boolean',
|
||||||
|
short: 'f'
|
||||||
|
},
|
||||||
|
bar: {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const {
|
||||||
|
values,
|
||||||
|
positionals
|
||||||
|
} = parseArgs({ args, options });
|
||||||
|
console.log(values, positionals);
|
||||||
|
// Prints: [Object: null prototype] { foo: true, bar: 'b' } []
|
||||||
|
```
|
||||||
|
|
||||||
|
```cjs
|
||||||
|
const { parseArgs } = require('node:util');
|
||||||
|
const args = ['-f', '--bar', 'b'];
|
||||||
|
const options = {
|
||||||
|
foo: {
|
||||||
|
type: 'boolean',
|
||||||
|
short: 'f'
|
||||||
|
},
|
||||||
|
bar: {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const {
|
||||||
|
values,
|
||||||
|
positionals
|
||||||
|
} = parseArgs({ args, options });
|
||||||
|
console.log(values, positionals);
|
||||||
|
// Prints: [Object: null prototype] { foo: true, bar: 'b' } []
|
||||||
|
```
|
||||||
|
|
||||||
|
`util.parseArgs` is experimental and behavior may change. Join the
|
||||||
|
conversation in [pkgjs/parseargs][] to contribute to the design.
|
||||||
|
|
||||||
|
### `parseArgs` `tokens`
|
||||||
|
|
||||||
|
Detailed parse information is available for adding custom behaviours by
|
||||||
|
specifying `tokens: true` in the configuration.
|
||||||
|
The returned tokens have properties describing:
|
||||||
|
|
||||||
|
* all tokens
|
||||||
|
* `kind` {string} One of 'option', 'positional', or 'option-terminator'.
|
||||||
|
* `index` {number} Index of element in `args` containing token. So the
|
||||||
|
source argument for a token is `args[token.index]`.
|
||||||
|
* option tokens
|
||||||
|
* `name` {string} Long name of option.
|
||||||
|
* `rawName` {string} How option used in args, like `-f` of `--foo`.
|
||||||
|
* `value` {string | undefined} Option value specified in args.
|
||||||
|
Undefined for boolean options.
|
||||||
|
* `inlineValue` {boolean | undefined} Whether option value specified inline,
|
||||||
|
like `--foo=bar`.
|
||||||
|
* positional tokens
|
||||||
|
* `value` {string} The value of the positional argument in args (i.e. `args[index]`).
|
||||||
|
* option-terminator token
|
||||||
|
|
||||||
|
The returned tokens are in the order encountered in the input args. Options
|
||||||
|
that appear more than once in args produce a token for each use. Short option
|
||||||
|
groups like `-xy` expand to a token for each option. So `-xxx` produces
|
||||||
|
three tokens.
|
||||||
|
|
||||||
|
For example to use the returned tokens to add support for a negated option
|
||||||
|
like `--no-color`, the tokens can be reprocessed to change the value stored
|
||||||
|
for the negated option.
|
||||||
|
|
||||||
|
```mjs
|
||||||
|
import { parseArgs } from 'node:util';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
'color': { type: 'boolean' },
|
||||||
|
'no-color': { type: 'boolean' },
|
||||||
|
'logfile': { type: 'string' },
|
||||||
|
'no-logfile': { type: 'boolean' },
|
||||||
|
};
|
||||||
|
const { values, tokens } = parseArgs({ options, tokens: true });
|
||||||
|
|
||||||
|
// Reprocess the option tokens and overwrite the returned values.
|
||||||
|
tokens
|
||||||
|
.filter((token) => token.kind === 'option')
|
||||||
|
.forEach((token) => {
|
||||||
|
if (token.name.startsWith('no-')) {
|
||||||
|
// Store foo:false for --no-foo
|
||||||
|
const positiveName = token.name.slice(3);
|
||||||
|
values[positiveName] = false;
|
||||||
|
delete values[token.name];
|
||||||
|
} else {
|
||||||
|
// Resave value so last one wins if both --foo and --no-foo.
|
||||||
|
values[token.name] = token.value ?? true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const color = values.color;
|
||||||
|
const logfile = values.logfile ?? 'default.log';
|
||||||
|
|
||||||
|
console.log({ logfile, color });
|
||||||
|
```
|
||||||
|
|
||||||
|
```cjs
|
||||||
|
const { parseArgs } = require('node:util');
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
'color': { type: 'boolean' },
|
||||||
|
'no-color': { type: 'boolean' },
|
||||||
|
'logfile': { type: 'string' },
|
||||||
|
'no-logfile': { type: 'boolean' },
|
||||||
|
};
|
||||||
|
const { values, tokens } = parseArgs({ options, tokens: true });
|
||||||
|
|
||||||
|
// Reprocess the option tokens and overwrite the returned values.
|
||||||
|
tokens
|
||||||
|
.filter((token) => token.kind === 'option')
|
||||||
|
.forEach((token) => {
|
||||||
|
if (token.name.startsWith('no-')) {
|
||||||
|
// Store foo:false for --no-foo
|
||||||
|
const positiveName = token.name.slice(3);
|
||||||
|
values[positiveName] = false;
|
||||||
|
delete values[token.name];
|
||||||
|
} else {
|
||||||
|
// Resave value so last one wins if both --foo and --no-foo.
|
||||||
|
values[token.name] = token.value ?? true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const color = values.color;
|
||||||
|
const logfile = values.logfile ?? 'default.log';
|
||||||
|
|
||||||
|
console.log({ logfile, color });
|
||||||
|
```
|
||||||
|
|
||||||
|
Example usage showing negated options, and when an option is used
|
||||||
|
multiple ways then last one wins.
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ node negate.js
|
||||||
|
{ logfile: 'default.log', color: undefined }
|
||||||
|
$ node negate.js --no-logfile --no-color
|
||||||
|
{ logfile: false, color: false }
|
||||||
|
$ node negate.js --logfile=test.log --color
|
||||||
|
{ logfile: 'test.log', color: true }
|
||||||
|
$ node negate.js --no-logfile --logfile=test.log --color --no-color
|
||||||
|
{ logfile: 'test.log', color: false }
|
||||||
|
```
|
||||||
|
|
||||||
|
-----
|
||||||
|
|
||||||
|
<!-- omit in toc -->
|
||||||
|
## Table of Contents
|
||||||
|
- [`util.parseArgs([config])`](#utilparseargsconfig)
|
||||||
|
- [Scope](#scope)
|
||||||
|
- [Version Matchups](#version-matchups)
|
||||||
|
- [🚀 Getting Started](#-getting-started)
|
||||||
|
- [🙌 Contributing](#-contributing)
|
||||||
|
- [💡 `process.mainArgs` Proposal](#-processmainargs-proposal)
|
||||||
|
- [Implementation:](#implementation)
|
||||||
|
- [📃 Examples](#-examples)
|
||||||
|
- [F.A.Qs](#faqs)
|
||||||
|
- [Links & Resources](#links--resources)
|
||||||
|
|
||||||
|
-----
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
It is already possible to build great arg parsing modules on top of what Node.js provides; the prickly API is abstracted away by these modules. Thus, process.parseArgs() is not necessarily intended for library authors; it is intended for developers of simple CLI tools, ad-hoc scripts, deployed Node.js applications, and learning materials.
|
||||||
|
|
||||||
|
It is exceedingly difficult to provide an API which would both be friendly to these Node.js users while being extensible enough for libraries to build upon. We chose to prioritize these use cases because these are currently not well-served by Node.js' API.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
## Version Matchups
|
||||||
|
|
||||||
|
| Node.js | @pkgjs/parseArgs |
|
||||||
|
| -- | -- |
|
||||||
|
| [v18.3.0](https://nodejs.org/docs/latest-v18.x/api/util.html#utilparseargsconfig) | [v0.9.1](https://github.com/pkgjs/parseargs/tree/v0.9.1#utilparseargsconfig) |
|
||||||
|
| [v16.17.0](https://nodejs.org/dist/latest-v16.x/docs/api/util.html#utilparseargsconfig), [v18.7.0](https://nodejs.org/docs/latest-v18.x/api/util.html#utilparseargsconfig) | [0.10.0](https://github.com/pkgjs/parseargs/tree/v0.10.0#utilparseargsconfig) |
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
## 🚀 Getting Started
|
||||||
|
|
||||||
|
1. **Install dependencies.**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
2. **Open the index.js file and start editing!**
|
||||||
|
|
||||||
|
3. **Test your code by calling parseArgs through our test file**
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm test
|
||||||
|
```
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
## 🙌 Contributing
|
||||||
|
|
||||||
|
Any person who wants to contribute to the initiative is welcome! Please first read the [Contributing Guide](CONTRIBUTING.md)
|
||||||
|
|
||||||
|
Additionally, reading the [`Examples w/ Output`](#-examples-w-output) section of this document will be the best way to familiarize yourself with the target expected behavior for parseArgs() once it is fully implemented.
|
||||||
|
|
||||||
|
This package was implemented using [tape](https://www.npmjs.com/package/tape) as its test harness.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
## 💡 `process.mainArgs` Proposal
|
||||||
|
|
||||||
|
> Note: This can be moved forward independently of the `util.parseArgs()` proposal/work.
|
||||||
|
|
||||||
|
### Implementation:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
process.mainArgs = process.argv.slice(process._exec ? 1 : 2)
|
||||||
|
```
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
## 📃 Examples
|
||||||
|
|
||||||
|
```js
|
||||||
|
const { parseArgs } = require('@pkgjs/parseargs');
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
const { parseArgs } = require('@pkgjs/parseargs');
|
||||||
|
// specify the options that may be used
|
||||||
|
const options = {
|
||||||
|
foo: { type: 'string'},
|
||||||
|
bar: { type: 'boolean' },
|
||||||
|
};
|
||||||
|
const args = ['--foo=a', '--bar'];
|
||||||
|
const { values, positionals } = parseArgs({ args, options });
|
||||||
|
// values = { foo: 'a', bar: true }
|
||||||
|
// positionals = []
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
const { parseArgs } = require('@pkgjs/parseargs');
|
||||||
|
// type:string & multiple
|
||||||
|
const options = {
|
||||||
|
foo: {
|
||||||
|
type: 'string',
|
||||||
|
multiple: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const args = ['--foo=a', '--foo', 'b'];
|
||||||
|
const { values, positionals } = parseArgs({ args, options });
|
||||||
|
// values = { foo: [ 'a', 'b' ] }
|
||||||
|
// positionals = []
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
const { parseArgs } = require('@pkgjs/parseargs');
|
||||||
|
// shorts
|
||||||
|
const options = {
|
||||||
|
foo: {
|
||||||
|
short: 'f',
|
||||||
|
type: 'boolean'
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const args = ['-f', 'b'];
|
||||||
|
const { values, positionals } = parseArgs({ args, options, allowPositionals: true });
|
||||||
|
// values = { foo: true }
|
||||||
|
// positionals = ['b']
|
||||||
|
```
|
||||||
|
|
||||||
|
```js
|
||||||
|
const { parseArgs } = require('@pkgjs/parseargs');
|
||||||
|
// unconfigured
|
||||||
|
const options = {};
|
||||||
|
const args = ['-f', '--foo=a', '--bar', 'b'];
|
||||||
|
const { values, positionals } = parseArgs({ strict: false, args, options, allowPositionals: true });
|
||||||
|
// values = { f: true, foo: 'a', bar: true }
|
||||||
|
// positionals = ['b']
|
||||||
|
```
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
## F.A.Qs
|
||||||
|
|
||||||
|
- Is `cmd --foo=bar baz` the same as `cmd baz --foo=bar`?
|
||||||
|
- yes
|
||||||
|
- Does the parser execute a function?
|
||||||
|
- no
|
||||||
|
- Does the parser execute one of several functions, depending on input?
|
||||||
|
- no
|
||||||
|
- Can subcommands take options that are distinct from the main command?
|
||||||
|
- no
|
||||||
|
- Does it output generated help when no options match?
|
||||||
|
- no
|
||||||
|
- Does it generated short usage? Like: `usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]`
|
||||||
|
- no (no usage/help at all)
|
||||||
|
- Does the user provide the long usage text? For each option? For the whole command?
|
||||||
|
- no
|
||||||
|
- Do subcommands (if implemented) have their own usage output?
|
||||||
|
- no
|
||||||
|
- Does usage print if the user runs `cmd --help`?
|
||||||
|
- no
|
||||||
|
- Does it set `process.exitCode`?
|
||||||
|
- no
|
||||||
|
- Does usage print to stderr or stdout?
|
||||||
|
- N/A
|
||||||
|
- Does it check types? (Say, specify that an option is a boolean, number, etc.)
|
||||||
|
- no
|
||||||
|
- Can an option have more than one type? (string or false, for example)
|
||||||
|
- no
|
||||||
|
- Can the user define a type? (Say, `type: path` to call `path.resolve()` on the argument.)
|
||||||
|
- no
|
||||||
|
- Does a `--foo=0o22` mean 0, 22, 18, or "0o22"?
|
||||||
|
- `"0o22"`
|
||||||
|
- Does it coerce types?
|
||||||
|
- no
|
||||||
|
- Does `--no-foo` coerce to `--foo=false`? For all options? Only boolean options?
|
||||||
|
- no, it sets `{values:{'no-foo': true}}`
|
||||||
|
- Is `--foo` the same as `--foo=true`? Only for known booleans? Only at the end?
|
||||||
|
- no, they are not the same. There is no special handling of `true` as a value so it is just another string.
|
||||||
|
- Does it read environment variables? Ie, is `FOO=1 cmd` the same as `cmd --foo=1`?
|
||||||
|
- no
|
||||||
|
- Do unknown arguments raise an error? Are they parsed? Are they treated as positional arguments?
|
||||||
|
- no, they are parsed, not treated as positionals
|
||||||
|
- Does `--` signal the end of options?
|
||||||
|
- yes
|
||||||
|
- Is `--` included as a positional?
|
||||||
|
- no
|
||||||
|
- Is `program -- foo` the same as `program foo`?
|
||||||
|
- yes, both store `{positionals:['foo']}`
|
||||||
|
- Does the API specify whether a `--` was present/relevant?
|
||||||
|
- no
|
||||||
|
- Is `-bar` the same as `--bar`?
|
||||||
|
- no, `-bar` is a short option or options, with expansion logic that follows the
|
||||||
|
[Utility Syntax Guidelines in POSIX.1-2017](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html). `-bar` expands to `-b`, `-a`, `-r`.
|
||||||
|
- Is `---foo` the same as `--foo`?
|
||||||
|
- no
|
||||||
|
- the first is a long option named `'-foo'`
|
||||||
|
- the second is a long option named `'foo'`
|
||||||
|
- Is `-` a positional? ie, `bash some-test.sh | tap -`
|
||||||
|
- yes
|
||||||
|
|
||||||
|
## Links & Resources
|
||||||
|
|
||||||
|
* [Initial Tooling Issue](https://github.com/nodejs/tooling/issues/19)
|
||||||
|
* [Initial Proposal](https://github.com/nodejs/node/pull/35015)
|
||||||
|
* [parseArgs Proposal](https://github.com/nodejs/node/pull/42675)
|
||||||
|
|
||||||
|
[coverage-image]: https://img.shields.io/nycrc/pkgjs/parseargs
|
||||||
|
[coverage-url]: https://github.com/pkgjs/parseargs/blob/main/.nycrc
|
||||||
|
[pkgjs/parseargs]: https://github.com/pkgjs/parseargs
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// This example shows how to understand if a default value is used or not.
|
||||||
|
|
||||||
|
// 1. const { parseArgs } = require('node:util'); // from node
|
||||||
|
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
|
||||||
|
const { parseArgs } = require('..'); // in repo
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
file: { short: 'f', type: 'string', default: 'FOO' },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { values, tokens } = parseArgs({ options, tokens: true });
|
||||||
|
|
||||||
|
const isFileDefault = !tokens.some((token) => token.kind === 'option' &&
|
||||||
|
token.name === 'file'
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(values);
|
||||||
|
console.log(`Is the file option [${values.file}] the default value? ${isFileDefault}`);
|
||||||
|
|
||||||
|
// Try the following:
|
||||||
|
// node is-default-value.js
|
||||||
|
// node is-default-value.js -f FILE
|
||||||
|
// node is-default-value.js --file FILE
|
||||||
+35
@@ -0,0 +1,35 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// This is an example of using tokens to add a custom behaviour.
|
||||||
|
//
|
||||||
|
// Require the use of `=` for long options and values by blocking
|
||||||
|
// the use of space separated values.
|
||||||
|
// So allow `--foo=bar`, and not allow `--foo bar`.
|
||||||
|
//
|
||||||
|
// Note: this is not a common behaviour, most CLIs allow both forms.
|
||||||
|
|
||||||
|
// 1. const { parseArgs } = require('node:util'); // from node
|
||||||
|
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
|
||||||
|
const { parseArgs } = require('..'); // in repo
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
file: { short: 'f', type: 'string' },
|
||||||
|
log: { type: 'string' },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { values, tokens } = parseArgs({ options, tokens: true });
|
||||||
|
|
||||||
|
const badToken = tokens.find((token) => token.kind === 'option' &&
|
||||||
|
token.value != null &&
|
||||||
|
token.rawName.startsWith('--') &&
|
||||||
|
!token.inlineValue
|
||||||
|
);
|
||||||
|
if (badToken) {
|
||||||
|
throw new Error(`Option value for '${badToken.rawName}' must be inline, like '${badToken.rawName}=VALUE'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(values);
|
||||||
|
|
||||||
|
// Try the following:
|
||||||
|
// node limit-long-syntax.js -f FILE --log=LOG
|
||||||
|
// node limit-long-syntax.js --file FILE
|
||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// This example is used in the documentation.
|
||||||
|
|
||||||
|
// How might I add my own support for --no-foo?
|
||||||
|
|
||||||
|
// 1. const { parseArgs } = require('node:util'); // from node
|
||||||
|
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
|
||||||
|
const { parseArgs } = require('..'); // in repo
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
'color': { type: 'boolean' },
|
||||||
|
'no-color': { type: 'boolean' },
|
||||||
|
'logfile': { type: 'string' },
|
||||||
|
'no-logfile': { type: 'boolean' },
|
||||||
|
};
|
||||||
|
const { values, tokens } = parseArgs({ options, tokens: true });
|
||||||
|
|
||||||
|
// Reprocess the option tokens and overwrite the returned values.
|
||||||
|
tokens
|
||||||
|
.filter((token) => token.kind === 'option')
|
||||||
|
.forEach((token) => {
|
||||||
|
if (token.name.startsWith('no-')) {
|
||||||
|
// Store foo:false for --no-foo
|
||||||
|
const positiveName = token.name.slice(3);
|
||||||
|
values[positiveName] = false;
|
||||||
|
delete values[token.name];
|
||||||
|
} else {
|
||||||
|
// Resave value so last one wins if both --foo and --no-foo.
|
||||||
|
values[token.name] = token.value ?? true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const color = values.color;
|
||||||
|
const logfile = values.logfile ?? 'default.log';
|
||||||
|
|
||||||
|
console.log({ logfile, color });
|
||||||
|
|
||||||
|
// Try the following:
|
||||||
|
// node negate.js
|
||||||
|
// node negate.js --no-logfile --no-color
|
||||||
|
// negate.js --logfile=test.log --color
|
||||||
|
// node negate.js --no-logfile --logfile=test.log --color --no-color
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// This is an example of using tokens to add a custom behaviour.
|
||||||
|
//
|
||||||
|
// Throw an error if an option is used more than once.
|
||||||
|
|
||||||
|
// 1. const { parseArgs } = require('node:util'); // from node
|
||||||
|
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
|
||||||
|
const { parseArgs } = require('..'); // in repo
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
ding: { type: 'boolean', short: 'd' },
|
||||||
|
beep: { type: 'boolean', short: 'b' }
|
||||||
|
};
|
||||||
|
const { values, tokens } = parseArgs({ options, tokens: true });
|
||||||
|
|
||||||
|
const seenBefore = new Set();
|
||||||
|
tokens.forEach((token) => {
|
||||||
|
if (token.kind !== 'option') return;
|
||||||
|
if (seenBefore.has(token.name)) {
|
||||||
|
throw new Error(`option '${token.name}' used multiple times`);
|
||||||
|
}
|
||||||
|
seenBefore.add(token.name);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(values);
|
||||||
|
|
||||||
|
// Try the following:
|
||||||
|
// node no-repeated-options --ding --beep
|
||||||
|
// node no-repeated-options --beep -b
|
||||||
|
// node no-repeated-options -ddd
|
||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
// This is an example of using tokens to add a custom behaviour.
|
||||||
|
//
|
||||||
|
// This adds a option order check so that --some-unstable-option
|
||||||
|
// may only be used after --enable-experimental-options
|
||||||
|
//
|
||||||
|
// Note: this is not a common behaviour, the order of different options
|
||||||
|
// does not usually matter.
|
||||||
|
|
||||||
|
import { parseArgs } from '../index.js';
|
||||||
|
|
||||||
|
function findTokenIndex(tokens, target) {
|
||||||
|
return tokens.findIndex((token) => token.kind === 'option' &&
|
||||||
|
token.name === target
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const experimentalName = 'enable-experimental-options';
|
||||||
|
const unstableName = 'some-unstable-option';
|
||||||
|
|
||||||
|
const options = {
|
||||||
|
[experimentalName]: { type: 'boolean' },
|
||||||
|
[unstableName]: { type: 'boolean' },
|
||||||
|
};
|
||||||
|
|
||||||
|
const { values, tokens } = parseArgs({ options, tokens: true });
|
||||||
|
|
||||||
|
const experimentalIndex = findTokenIndex(tokens, experimentalName);
|
||||||
|
const unstableIndex = findTokenIndex(tokens, unstableName);
|
||||||
|
if (unstableIndex !== -1 &&
|
||||||
|
((experimentalIndex === -1) || (unstableIndex < experimentalIndex))) {
|
||||||
|
throw new Error(`'--${experimentalName}' must be specified before '--${unstableName}'`);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(values);
|
||||||
|
|
||||||
|
/* eslint-disable max-len */
|
||||||
|
// Try the following:
|
||||||
|
// node ordered-options.mjs
|
||||||
|
// node ordered-options.mjs --some-unstable-option
|
||||||
|
// node ordered-options.mjs --some-unstable-option --enable-experimental-options
|
||||||
|
// node ordered-options.mjs --enable-experimental-options --some-unstable-option
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// This example is used in the documentation.
|
||||||
|
|
||||||
|
// 1. const { parseArgs } = require('node:util'); // from node
|
||||||
|
// 2. const { parseArgs } = require('@pkgjs/parseargs'); // from package
|
||||||
|
const { parseArgs } = require('..'); // in repo
|
||||||
|
|
||||||
|
const args = ['-f', '--bar', 'b'];
|
||||||
|
const options = {
|
||||||
|
foo: {
|
||||||
|
type: 'boolean',
|
||||||
|
short: 'f'
|
||||||
|
},
|
||||||
|
bar: {
|
||||||
|
type: 'string'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const {
|
||||||
|
values,
|
||||||
|
positionals
|
||||||
|
} = parseArgs({ args, options });
|
||||||
|
console.log(values, positionals);
|
||||||
|
|
||||||
|
// Try the following:
|
||||||
|
// node simple-hard-coded.js
|
||||||
+396
@@ -0,0 +1,396 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const {
|
||||||
|
ArrayPrototypeForEach,
|
||||||
|
ArrayPrototypeIncludes,
|
||||||
|
ArrayPrototypeMap,
|
||||||
|
ArrayPrototypePush,
|
||||||
|
ArrayPrototypePushApply,
|
||||||
|
ArrayPrototypeShift,
|
||||||
|
ArrayPrototypeSlice,
|
||||||
|
ArrayPrototypeUnshiftApply,
|
||||||
|
ObjectEntries,
|
||||||
|
ObjectPrototypeHasOwnProperty: ObjectHasOwn,
|
||||||
|
StringPrototypeCharAt,
|
||||||
|
StringPrototypeIndexOf,
|
||||||
|
StringPrototypeSlice,
|
||||||
|
StringPrototypeStartsWith,
|
||||||
|
} = require('./internal/primordials');
|
||||||
|
|
||||||
|
const {
|
||||||
|
validateArray,
|
||||||
|
validateBoolean,
|
||||||
|
validateBooleanArray,
|
||||||
|
validateObject,
|
||||||
|
validateString,
|
||||||
|
validateStringArray,
|
||||||
|
validateUnion,
|
||||||
|
} = require('./internal/validators');
|
||||||
|
|
||||||
|
const {
|
||||||
|
kEmptyObject,
|
||||||
|
} = require('./internal/util');
|
||||||
|
|
||||||
|
const {
|
||||||
|
findLongOptionForShort,
|
||||||
|
isLoneLongOption,
|
||||||
|
isLoneShortOption,
|
||||||
|
isLongOptionAndValue,
|
||||||
|
isOptionValue,
|
||||||
|
isOptionLikeValue,
|
||||||
|
isShortOptionAndValue,
|
||||||
|
isShortOptionGroup,
|
||||||
|
useDefaultValueOption,
|
||||||
|
objectGetOwn,
|
||||||
|
optionsGetOwn,
|
||||||
|
} = require('./utils');
|
||||||
|
|
||||||
|
const {
|
||||||
|
codes: {
|
||||||
|
ERR_INVALID_ARG_VALUE,
|
||||||
|
ERR_PARSE_ARGS_INVALID_OPTION_VALUE,
|
||||||
|
ERR_PARSE_ARGS_UNKNOWN_OPTION,
|
||||||
|
ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL,
|
||||||
|
},
|
||||||
|
} = require('./internal/errors');
|
||||||
|
|
||||||
|
function getMainArgs() {
|
||||||
|
// Work out where to slice process.argv for user supplied arguments.
|
||||||
|
|
||||||
|
// Check node options for scenarios where user CLI args follow executable.
|
||||||
|
const execArgv = process.execArgv;
|
||||||
|
if (ArrayPrototypeIncludes(execArgv, '-e') ||
|
||||||
|
ArrayPrototypeIncludes(execArgv, '--eval') ||
|
||||||
|
ArrayPrototypeIncludes(execArgv, '-p') ||
|
||||||
|
ArrayPrototypeIncludes(execArgv, '--print')) {
|
||||||
|
return ArrayPrototypeSlice(process.argv, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normally first two arguments are executable and script, then CLI arguments
|
||||||
|
return ArrayPrototypeSlice(process.argv, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In strict mode, throw for possible usage errors like --foo --bar
|
||||||
|
*
|
||||||
|
* @param {object} token - from tokens as available from parseArgs
|
||||||
|
*/
|
||||||
|
function checkOptionLikeValue(token) {
|
||||||
|
if (!token.inlineValue && isOptionLikeValue(token.value)) {
|
||||||
|
// Only show short example if user used short option.
|
||||||
|
const example = StringPrototypeStartsWith(token.rawName, '--') ?
|
||||||
|
`'${token.rawName}=-XYZ'` :
|
||||||
|
`'--${token.name}=-XYZ' or '${token.rawName}-XYZ'`;
|
||||||
|
const errorMessage = `Option '${token.rawName}' argument is ambiguous.
|
||||||
|
Did you forget to specify the option argument for '${token.rawName}'?
|
||||||
|
To specify an option argument starting with a dash use ${example}.`;
|
||||||
|
throw new ERR_PARSE_ARGS_INVALID_OPTION_VALUE(errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In strict mode, throw for usage errors.
|
||||||
|
*
|
||||||
|
* @param {object} config - from config passed to parseArgs
|
||||||
|
* @param {object} token - from tokens as available from parseArgs
|
||||||
|
*/
|
||||||
|
function checkOptionUsage(config, token) {
|
||||||
|
if (!ObjectHasOwn(config.options, token.name)) {
|
||||||
|
throw new ERR_PARSE_ARGS_UNKNOWN_OPTION(
|
||||||
|
token.rawName, config.allowPositionals);
|
||||||
|
}
|
||||||
|
|
||||||
|
const short = optionsGetOwn(config.options, token.name, 'short');
|
||||||
|
const shortAndLong = `${short ? `-${short}, ` : ''}--${token.name}`;
|
||||||
|
const type = optionsGetOwn(config.options, token.name, 'type');
|
||||||
|
if (type === 'string' && typeof token.value !== 'string') {
|
||||||
|
throw new ERR_PARSE_ARGS_INVALID_OPTION_VALUE(`Option '${shortAndLong} <value>' argument missing`);
|
||||||
|
}
|
||||||
|
// (Idiomatic test for undefined||null, expecting undefined.)
|
||||||
|
if (type === 'boolean' && token.value != null) {
|
||||||
|
throw new ERR_PARSE_ARGS_INVALID_OPTION_VALUE(`Option '${shortAndLong}' does not take an argument`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store the option value in `values`.
|
||||||
|
*
|
||||||
|
* @param {string} longOption - long option name e.g. 'foo'
|
||||||
|
* @param {string|undefined} optionValue - value from user args
|
||||||
|
* @param {object} options - option configs, from parseArgs({ options })
|
||||||
|
* @param {object} values - option values returned in `values` by parseArgs
|
||||||
|
*/
|
||||||
|
function storeOption(longOption, optionValue, options, values) {
|
||||||
|
if (longOption === '__proto__') {
|
||||||
|
return; // No. Just no.
|
||||||
|
}
|
||||||
|
|
||||||
|
// We store based on the option value rather than option type,
|
||||||
|
// preserving the users intent for author to deal with.
|
||||||
|
const newValue = optionValue ?? true;
|
||||||
|
if (optionsGetOwn(options, longOption, 'multiple')) {
|
||||||
|
// Always store value in array, including for boolean.
|
||||||
|
// values[longOption] starts out not present,
|
||||||
|
// first value is added as new array [newValue],
|
||||||
|
// subsequent values are pushed to existing array.
|
||||||
|
// (note: values has null prototype, so simpler usage)
|
||||||
|
if (values[longOption]) {
|
||||||
|
ArrayPrototypePush(values[longOption], newValue);
|
||||||
|
} else {
|
||||||
|
values[longOption] = [newValue];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
values[longOption] = newValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store the default option value in `values`.
|
||||||
|
*
|
||||||
|
* @param {string} longOption - long option name e.g. 'foo'
|
||||||
|
* @param {string
|
||||||
|
* | boolean
|
||||||
|
* | string[]
|
||||||
|
* | boolean[]} optionValue - default value from option config
|
||||||
|
* @param {object} values - option values returned in `values` by parseArgs
|
||||||
|
*/
|
||||||
|
function storeDefaultOption(longOption, optionValue, values) {
|
||||||
|
if (longOption === '__proto__') {
|
||||||
|
return; // No. Just no.
|
||||||
|
}
|
||||||
|
|
||||||
|
values[longOption] = optionValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process args and turn into identified tokens:
|
||||||
|
* - option (along with value, if any)
|
||||||
|
* - positional
|
||||||
|
* - option-terminator
|
||||||
|
*
|
||||||
|
* @param {string[]} args - from parseArgs({ args }) or mainArgs
|
||||||
|
* @param {object} options - option configs, from parseArgs({ options })
|
||||||
|
*/
|
||||||
|
function argsToTokens(args, options) {
|
||||||
|
const tokens = [];
|
||||||
|
let index = -1;
|
||||||
|
let groupCount = 0;
|
||||||
|
|
||||||
|
const remainingArgs = ArrayPrototypeSlice(args);
|
||||||
|
while (remainingArgs.length > 0) {
|
||||||
|
const arg = ArrayPrototypeShift(remainingArgs);
|
||||||
|
const nextArg = remainingArgs[0];
|
||||||
|
if (groupCount > 0)
|
||||||
|
groupCount--;
|
||||||
|
else
|
||||||
|
index++;
|
||||||
|
|
||||||
|
// Check if `arg` is an options terminator.
|
||||||
|
// Guideline 10 in https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
|
||||||
|
if (arg === '--') {
|
||||||
|
// Everything after a bare '--' is considered a positional argument.
|
||||||
|
ArrayPrototypePush(tokens, { kind: 'option-terminator', index });
|
||||||
|
ArrayPrototypePushApply(
|
||||||
|
tokens, ArrayPrototypeMap(remainingArgs, (arg) => {
|
||||||
|
return { kind: 'positional', index: ++index, value: arg };
|
||||||
|
})
|
||||||
|
);
|
||||||
|
break; // Finished processing args, leave while loop.
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoneShortOption(arg)) {
|
||||||
|
// e.g. '-f'
|
||||||
|
const shortOption = StringPrototypeCharAt(arg, 1);
|
||||||
|
const longOption = findLongOptionForShort(shortOption, options);
|
||||||
|
let value;
|
||||||
|
let inlineValue;
|
||||||
|
if (optionsGetOwn(options, longOption, 'type') === 'string' &&
|
||||||
|
isOptionValue(nextArg)) {
|
||||||
|
// e.g. '-f', 'bar'
|
||||||
|
value = ArrayPrototypeShift(remainingArgs);
|
||||||
|
inlineValue = false;
|
||||||
|
}
|
||||||
|
ArrayPrototypePush(
|
||||||
|
tokens,
|
||||||
|
{ kind: 'option', name: longOption, rawName: arg,
|
||||||
|
index, value, inlineValue });
|
||||||
|
if (value != null) ++index;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isShortOptionGroup(arg, options)) {
|
||||||
|
// Expand -fXzy to -f -X -z -y
|
||||||
|
const expanded = [];
|
||||||
|
for (let index = 1; index < arg.length; index++) {
|
||||||
|
const shortOption = StringPrototypeCharAt(arg, index);
|
||||||
|
const longOption = findLongOptionForShort(shortOption, options);
|
||||||
|
if (optionsGetOwn(options, longOption, 'type') !== 'string' ||
|
||||||
|
index === arg.length - 1) {
|
||||||
|
// Boolean option, or last short in group. Well formed.
|
||||||
|
ArrayPrototypePush(expanded, `-${shortOption}`);
|
||||||
|
} else {
|
||||||
|
// String option in middle. Yuck.
|
||||||
|
// Expand -abfFILE to -a -b -fFILE
|
||||||
|
ArrayPrototypePush(expanded, `-${StringPrototypeSlice(arg, index)}`);
|
||||||
|
break; // finished short group
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ArrayPrototypeUnshiftApply(remainingArgs, expanded);
|
||||||
|
groupCount = expanded.length;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isShortOptionAndValue(arg, options)) {
|
||||||
|
// e.g. -fFILE
|
||||||
|
const shortOption = StringPrototypeCharAt(arg, 1);
|
||||||
|
const longOption = findLongOptionForShort(shortOption, options);
|
||||||
|
const value = StringPrototypeSlice(arg, 2);
|
||||||
|
ArrayPrototypePush(
|
||||||
|
tokens,
|
||||||
|
{ kind: 'option', name: longOption, rawName: `-${shortOption}`,
|
||||||
|
index, value, inlineValue: true });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLoneLongOption(arg)) {
|
||||||
|
// e.g. '--foo'
|
||||||
|
const longOption = StringPrototypeSlice(arg, 2);
|
||||||
|
let value;
|
||||||
|
let inlineValue;
|
||||||
|
if (optionsGetOwn(options, longOption, 'type') === 'string' &&
|
||||||
|
isOptionValue(nextArg)) {
|
||||||
|
// e.g. '--foo', 'bar'
|
||||||
|
value = ArrayPrototypeShift(remainingArgs);
|
||||||
|
inlineValue = false;
|
||||||
|
}
|
||||||
|
ArrayPrototypePush(
|
||||||
|
tokens,
|
||||||
|
{ kind: 'option', name: longOption, rawName: arg,
|
||||||
|
index, value, inlineValue });
|
||||||
|
if (value != null) ++index;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isLongOptionAndValue(arg)) {
|
||||||
|
// e.g. --foo=bar
|
||||||
|
const equalIndex = StringPrototypeIndexOf(arg, '=');
|
||||||
|
const longOption = StringPrototypeSlice(arg, 2, equalIndex);
|
||||||
|
const value = StringPrototypeSlice(arg, equalIndex + 1);
|
||||||
|
ArrayPrototypePush(
|
||||||
|
tokens,
|
||||||
|
{ kind: 'option', name: longOption, rawName: `--${longOption}`,
|
||||||
|
index, value, inlineValue: true });
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayPrototypePush(tokens, { kind: 'positional', index, value: arg });
|
||||||
|
}
|
||||||
|
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parseArgs = (config = kEmptyObject) => {
|
||||||
|
const args = objectGetOwn(config, 'args') ?? getMainArgs();
|
||||||
|
const strict = objectGetOwn(config, 'strict') ?? true;
|
||||||
|
const allowPositionals = objectGetOwn(config, 'allowPositionals') ?? !strict;
|
||||||
|
const returnTokens = objectGetOwn(config, 'tokens') ?? false;
|
||||||
|
const options = objectGetOwn(config, 'options') ?? { __proto__: null };
|
||||||
|
// Bundle these up for passing to strict-mode checks.
|
||||||
|
const parseConfig = { args, strict, options, allowPositionals };
|
||||||
|
|
||||||
|
// Validate input configuration.
|
||||||
|
validateArray(args, 'args');
|
||||||
|
validateBoolean(strict, 'strict');
|
||||||
|
validateBoolean(allowPositionals, 'allowPositionals');
|
||||||
|
validateBoolean(returnTokens, 'tokens');
|
||||||
|
validateObject(options, 'options');
|
||||||
|
ArrayPrototypeForEach(
|
||||||
|
ObjectEntries(options),
|
||||||
|
({ 0: longOption, 1: optionConfig }) => {
|
||||||
|
validateObject(optionConfig, `options.${longOption}`);
|
||||||
|
|
||||||
|
// type is required
|
||||||
|
const optionType = objectGetOwn(optionConfig, 'type');
|
||||||
|
validateUnion(optionType, `options.${longOption}.type`, ['string', 'boolean']);
|
||||||
|
|
||||||
|
if (ObjectHasOwn(optionConfig, 'short')) {
|
||||||
|
const shortOption = optionConfig.short;
|
||||||
|
validateString(shortOption, `options.${longOption}.short`);
|
||||||
|
if (shortOption.length !== 1) {
|
||||||
|
throw new ERR_INVALID_ARG_VALUE(
|
||||||
|
`options.${longOption}.short`,
|
||||||
|
shortOption,
|
||||||
|
'must be a single character'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const multipleOption = objectGetOwn(optionConfig, 'multiple');
|
||||||
|
if (ObjectHasOwn(optionConfig, 'multiple')) {
|
||||||
|
validateBoolean(multipleOption, `options.${longOption}.multiple`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultValue = objectGetOwn(optionConfig, 'default');
|
||||||
|
if (defaultValue !== undefined) {
|
||||||
|
let validator;
|
||||||
|
switch (optionType) {
|
||||||
|
case 'string':
|
||||||
|
validator = multipleOption ? validateStringArray : validateString;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'boolean':
|
||||||
|
validator = multipleOption ? validateBooleanArray : validateBoolean;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
validator(defaultValue, `options.${longOption}.default`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Phase 1: identify tokens
|
||||||
|
const tokens = argsToTokens(args, options);
|
||||||
|
|
||||||
|
// Phase 2: process tokens into parsed option values and positionals
|
||||||
|
const result = {
|
||||||
|
values: { __proto__: null },
|
||||||
|
positionals: [],
|
||||||
|
};
|
||||||
|
if (returnTokens) {
|
||||||
|
result.tokens = tokens;
|
||||||
|
}
|
||||||
|
ArrayPrototypeForEach(tokens, (token) => {
|
||||||
|
if (token.kind === 'option') {
|
||||||
|
if (strict) {
|
||||||
|
checkOptionUsage(parseConfig, token);
|
||||||
|
checkOptionLikeValue(token);
|
||||||
|
}
|
||||||
|
storeOption(token.name, token.value, options, result.values);
|
||||||
|
} else if (token.kind === 'positional') {
|
||||||
|
if (!allowPositionals) {
|
||||||
|
throw new ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL(token.value);
|
||||||
|
}
|
||||||
|
ArrayPrototypePush(result.positionals, token.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Phase 3: fill in default values for missing args
|
||||||
|
ArrayPrototypeForEach(ObjectEntries(options), ({ 0: longOption,
|
||||||
|
1: optionConfig }) => {
|
||||||
|
const mustSetDefault = useDefaultValueOption(longOption,
|
||||||
|
optionConfig,
|
||||||
|
result.values);
|
||||||
|
if (mustSetDefault) {
|
||||||
|
storeDefaultOption(longOption,
|
||||||
|
objectGetOwn(optionConfig, 'default'),
|
||||||
|
result.values);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
parseArgs,
|
||||||
|
};
|
||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
class ERR_INVALID_ARG_TYPE extends TypeError {
|
||||||
|
constructor(name, expected, actual) {
|
||||||
|
super(`${name} must be ${expected} got ${actual}`);
|
||||||
|
this.code = 'ERR_INVALID_ARG_TYPE';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ERR_INVALID_ARG_VALUE extends TypeError {
|
||||||
|
constructor(arg1, arg2, expected) {
|
||||||
|
super(`The property ${arg1} ${expected}. Received '${arg2}'`);
|
||||||
|
this.code = 'ERR_INVALID_ARG_VALUE';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ERR_PARSE_ARGS_INVALID_OPTION_VALUE extends Error {
|
||||||
|
constructor(message) {
|
||||||
|
super(message);
|
||||||
|
this.code = 'ERR_PARSE_ARGS_INVALID_OPTION_VALUE';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ERR_PARSE_ARGS_UNKNOWN_OPTION extends Error {
|
||||||
|
constructor(option, allowPositionals) {
|
||||||
|
const suggestDashDash = allowPositionals ? `. To specify a positional argument starting with a '-', place it at the end of the command after '--', as in '-- ${JSON.stringify(option)}` : '';
|
||||||
|
super(`Unknown option '${option}'${suggestDashDash}`);
|
||||||
|
this.code = 'ERR_PARSE_ARGS_UNKNOWN_OPTION';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL extends Error {
|
||||||
|
constructor(positional) {
|
||||||
|
super(`Unexpected argument '${positional}'. This command does not take positional arguments`);
|
||||||
|
this.code = 'ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
codes: {
|
||||||
|
ERR_INVALID_ARG_TYPE,
|
||||||
|
ERR_INVALID_ARG_VALUE,
|
||||||
|
ERR_PARSE_ARGS_INVALID_OPTION_VALUE,
|
||||||
|
ERR_PARSE_ARGS_UNKNOWN_OPTION,
|
||||||
|
ERR_PARSE_ARGS_UNEXPECTED_POSITIONAL,
|
||||||
|
}
|
||||||
|
};
|
||||||
+393
@@ -0,0 +1,393 @@
|
|||||||
|
/*
|
||||||
|
This file is copied from https://github.com/nodejs/node/blob/v14.19.3/lib/internal/per_context/primordials.js
|
||||||
|
under the following license:
|
||||||
|
|
||||||
|
Copyright Node.js contributors. All rights reserved.
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
/* eslint-disable node-core/prefer-primordials */
|
||||||
|
|
||||||
|
// This file subclasses and stores the JS builtins that come from the VM
|
||||||
|
// so that Node.js's builtin modules do not need to later look these up from
|
||||||
|
// the global proxy, which can be mutated by users.
|
||||||
|
|
||||||
|
// Use of primordials have sometimes a dramatic impact on performance, please
|
||||||
|
// benchmark all changes made in performance-sensitive areas of the codebase.
|
||||||
|
// See: https://github.com/nodejs/node/pull/38248
|
||||||
|
|
||||||
|
const primordials = {};
|
||||||
|
|
||||||
|
const {
|
||||||
|
defineProperty: ReflectDefineProperty,
|
||||||
|
getOwnPropertyDescriptor: ReflectGetOwnPropertyDescriptor,
|
||||||
|
ownKeys: ReflectOwnKeys,
|
||||||
|
} = Reflect;
|
||||||
|
|
||||||
|
// `uncurryThis` is equivalent to `func => Function.prototype.call.bind(func)`.
|
||||||
|
// It is using `bind.bind(call)` to avoid using `Function.prototype.bind`
|
||||||
|
// and `Function.prototype.call` after it may have been mutated by users.
|
||||||
|
const { apply, bind, call } = Function.prototype;
|
||||||
|
const uncurryThis = bind.bind(call);
|
||||||
|
primordials.uncurryThis = uncurryThis;
|
||||||
|
|
||||||
|
// `applyBind` is equivalent to `func => Function.prototype.apply.bind(func)`.
|
||||||
|
// It is using `bind.bind(apply)` to avoid using `Function.prototype.bind`
|
||||||
|
// and `Function.prototype.apply` after it may have been mutated by users.
|
||||||
|
const applyBind = bind.bind(apply);
|
||||||
|
primordials.applyBind = applyBind;
|
||||||
|
|
||||||
|
// Methods that accept a variable number of arguments, and thus it's useful to
|
||||||
|
// also create `${prefix}${key}Apply`, which uses `Function.prototype.apply`,
|
||||||
|
// instead of `Function.prototype.call`, and thus doesn't require iterator
|
||||||
|
// destructuring.
|
||||||
|
const varargsMethods = [
|
||||||
|
// 'ArrayPrototypeConcat' is omitted, because it performs the spread
|
||||||
|
// on its own for arrays and array-likes with a truthy
|
||||||
|
// @@isConcatSpreadable symbol property.
|
||||||
|
'ArrayOf',
|
||||||
|
'ArrayPrototypePush',
|
||||||
|
'ArrayPrototypeUnshift',
|
||||||
|
// 'FunctionPrototypeCall' is omitted, since there's 'ReflectApply'
|
||||||
|
// and 'FunctionPrototypeApply'.
|
||||||
|
'MathHypot',
|
||||||
|
'MathMax',
|
||||||
|
'MathMin',
|
||||||
|
'StringPrototypeConcat',
|
||||||
|
'TypedArrayOf',
|
||||||
|
];
|
||||||
|
|
||||||
|
function getNewKey(key) {
|
||||||
|
return typeof key === 'symbol' ?
|
||||||
|
`Symbol${key.description[7].toUpperCase()}${key.description.slice(8)}` :
|
||||||
|
`${key[0].toUpperCase()}${key.slice(1)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyAccessor(dest, prefix, key, { enumerable, get, set }) {
|
||||||
|
ReflectDefineProperty(dest, `${prefix}Get${key}`, {
|
||||||
|
value: uncurryThis(get),
|
||||||
|
enumerable
|
||||||
|
});
|
||||||
|
if (set !== undefined) {
|
||||||
|
ReflectDefineProperty(dest, `${prefix}Set${key}`, {
|
||||||
|
value: uncurryThis(set),
|
||||||
|
enumerable
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyPropsRenamed(src, dest, prefix) {
|
||||||
|
for (const key of ReflectOwnKeys(src)) {
|
||||||
|
const newKey = getNewKey(key);
|
||||||
|
const desc = ReflectGetOwnPropertyDescriptor(src, key);
|
||||||
|
if ('get' in desc) {
|
||||||
|
copyAccessor(dest, prefix, newKey, desc);
|
||||||
|
} else {
|
||||||
|
const name = `${prefix}${newKey}`;
|
||||||
|
ReflectDefineProperty(dest, name, desc);
|
||||||
|
if (varargsMethods.includes(name)) {
|
||||||
|
ReflectDefineProperty(dest, `${name}Apply`, {
|
||||||
|
// `src` is bound as the `this` so that the static `this` points
|
||||||
|
// to the object it was defined on,
|
||||||
|
// e.g.: `ArrayOfApply` gets a `this` of `Array`:
|
||||||
|
value: applyBind(desc.value, src),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyPropsRenamedBound(src, dest, prefix) {
|
||||||
|
for (const key of ReflectOwnKeys(src)) {
|
||||||
|
const newKey = getNewKey(key);
|
||||||
|
const desc = ReflectGetOwnPropertyDescriptor(src, key);
|
||||||
|
if ('get' in desc) {
|
||||||
|
copyAccessor(dest, prefix, newKey, desc);
|
||||||
|
} else {
|
||||||
|
const { value } = desc;
|
||||||
|
if (typeof value === 'function') {
|
||||||
|
desc.value = value.bind(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = `${prefix}${newKey}`;
|
||||||
|
ReflectDefineProperty(dest, name, desc);
|
||||||
|
if (varargsMethods.includes(name)) {
|
||||||
|
ReflectDefineProperty(dest, `${name}Apply`, {
|
||||||
|
value: applyBind(value, src),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function copyPrototype(src, dest, prefix) {
|
||||||
|
for (const key of ReflectOwnKeys(src)) {
|
||||||
|
const newKey = getNewKey(key);
|
||||||
|
const desc = ReflectGetOwnPropertyDescriptor(src, key);
|
||||||
|
if ('get' in desc) {
|
||||||
|
copyAccessor(dest, prefix, newKey, desc);
|
||||||
|
} else {
|
||||||
|
const { value } = desc;
|
||||||
|
if (typeof value === 'function') {
|
||||||
|
desc.value = uncurryThis(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
const name = `${prefix}${newKey}`;
|
||||||
|
ReflectDefineProperty(dest, name, desc);
|
||||||
|
if (varargsMethods.includes(name)) {
|
||||||
|
ReflectDefineProperty(dest, `${name}Apply`, {
|
||||||
|
value: applyBind(value),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create copies of configurable value properties of the global object
|
||||||
|
[
|
||||||
|
'Proxy',
|
||||||
|
'globalThis',
|
||||||
|
].forEach((name) => {
|
||||||
|
// eslint-disable-next-line no-restricted-globals
|
||||||
|
primordials[name] = globalThis[name];
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create copies of URI handling functions
|
||||||
|
[
|
||||||
|
decodeURI,
|
||||||
|
decodeURIComponent,
|
||||||
|
encodeURI,
|
||||||
|
encodeURIComponent,
|
||||||
|
].forEach((fn) => {
|
||||||
|
primordials[fn.name] = fn;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create copies of the namespace objects
|
||||||
|
[
|
||||||
|
'JSON',
|
||||||
|
'Math',
|
||||||
|
'Proxy',
|
||||||
|
'Reflect',
|
||||||
|
].forEach((name) => {
|
||||||
|
// eslint-disable-next-line no-restricted-globals
|
||||||
|
copyPropsRenamed(global[name], primordials, name);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create copies of intrinsic objects
|
||||||
|
[
|
||||||
|
'Array',
|
||||||
|
'ArrayBuffer',
|
||||||
|
'BigInt',
|
||||||
|
'BigInt64Array',
|
||||||
|
'BigUint64Array',
|
||||||
|
'Boolean',
|
||||||
|
'DataView',
|
||||||
|
'Date',
|
||||||
|
'Error',
|
||||||
|
'EvalError',
|
||||||
|
'Float32Array',
|
||||||
|
'Float64Array',
|
||||||
|
'Function',
|
||||||
|
'Int16Array',
|
||||||
|
'Int32Array',
|
||||||
|
'Int8Array',
|
||||||
|
'Map',
|
||||||
|
'Number',
|
||||||
|
'Object',
|
||||||
|
'RangeError',
|
||||||
|
'ReferenceError',
|
||||||
|
'RegExp',
|
||||||
|
'Set',
|
||||||
|
'String',
|
||||||
|
'Symbol',
|
||||||
|
'SyntaxError',
|
||||||
|
'TypeError',
|
||||||
|
'URIError',
|
||||||
|
'Uint16Array',
|
||||||
|
'Uint32Array',
|
||||||
|
'Uint8Array',
|
||||||
|
'Uint8ClampedArray',
|
||||||
|
'WeakMap',
|
||||||
|
'WeakSet',
|
||||||
|
].forEach((name) => {
|
||||||
|
// eslint-disable-next-line no-restricted-globals
|
||||||
|
const original = global[name];
|
||||||
|
primordials[name] = original;
|
||||||
|
copyPropsRenamed(original, primordials, name);
|
||||||
|
copyPrototype(original.prototype, primordials, `${name}Prototype`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create copies of intrinsic objects that require a valid `this` to call
|
||||||
|
// static methods.
|
||||||
|
// Refs: https://www.ecma-international.org/ecma-262/#sec-promise.all
|
||||||
|
[
|
||||||
|
'Promise',
|
||||||
|
].forEach((name) => {
|
||||||
|
// eslint-disable-next-line no-restricted-globals
|
||||||
|
const original = global[name];
|
||||||
|
primordials[name] = original;
|
||||||
|
copyPropsRenamedBound(original, primordials, name);
|
||||||
|
copyPrototype(original.prototype, primordials, `${name}Prototype`);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Create copies of abstract intrinsic objects that are not directly exposed
|
||||||
|
// on the global object.
|
||||||
|
// Refs: https://tc39.es/ecma262/#sec-%typedarray%-intrinsic-object
|
||||||
|
[
|
||||||
|
{ name: 'TypedArray', original: Reflect.getPrototypeOf(Uint8Array) },
|
||||||
|
{ name: 'ArrayIterator', original: {
|
||||||
|
prototype: Reflect.getPrototypeOf(Array.prototype[Symbol.iterator]()),
|
||||||
|
} },
|
||||||
|
{ name: 'StringIterator', original: {
|
||||||
|
prototype: Reflect.getPrototypeOf(String.prototype[Symbol.iterator]()),
|
||||||
|
} },
|
||||||
|
].forEach(({ name, original }) => {
|
||||||
|
primordials[name] = original;
|
||||||
|
// The static %TypedArray% methods require a valid `this`, but can't be bound,
|
||||||
|
// as they need a subclass constructor as the receiver:
|
||||||
|
copyPrototype(original, primordials, name);
|
||||||
|
copyPrototype(original.prototype, primordials, `${name}Prototype`);
|
||||||
|
});
|
||||||
|
|
||||||
|
/* eslint-enable node-core/prefer-primordials */
|
||||||
|
|
||||||
|
const {
|
||||||
|
ArrayPrototypeForEach,
|
||||||
|
FunctionPrototypeCall,
|
||||||
|
Map,
|
||||||
|
ObjectFreeze,
|
||||||
|
ObjectSetPrototypeOf,
|
||||||
|
Set,
|
||||||
|
SymbolIterator,
|
||||||
|
WeakMap,
|
||||||
|
WeakSet,
|
||||||
|
} = primordials;
|
||||||
|
|
||||||
|
// Because these functions are used by `makeSafe`, which is exposed
|
||||||
|
// on the `primordials` object, it's important to use const references
|
||||||
|
// to the primordials that they use:
|
||||||
|
const createSafeIterator = (factory, next) => {
|
||||||
|
class SafeIterator {
|
||||||
|
constructor(iterable) {
|
||||||
|
this._iterator = factory(iterable);
|
||||||
|
}
|
||||||
|
next() {
|
||||||
|
return next(this._iterator);
|
||||||
|
}
|
||||||
|
[SymbolIterator]() {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ObjectSetPrototypeOf(SafeIterator.prototype, null);
|
||||||
|
ObjectFreeze(SafeIterator.prototype);
|
||||||
|
ObjectFreeze(SafeIterator);
|
||||||
|
return SafeIterator;
|
||||||
|
};
|
||||||
|
|
||||||
|
primordials.SafeArrayIterator = createSafeIterator(
|
||||||
|
primordials.ArrayPrototypeSymbolIterator,
|
||||||
|
primordials.ArrayIteratorPrototypeNext
|
||||||
|
);
|
||||||
|
primordials.SafeStringIterator = createSafeIterator(
|
||||||
|
primordials.StringPrototypeSymbolIterator,
|
||||||
|
primordials.StringIteratorPrototypeNext
|
||||||
|
);
|
||||||
|
|
||||||
|
const copyProps = (src, dest) => {
|
||||||
|
ArrayPrototypeForEach(ReflectOwnKeys(src), (key) => {
|
||||||
|
if (!ReflectGetOwnPropertyDescriptor(dest, key)) {
|
||||||
|
ReflectDefineProperty(
|
||||||
|
dest,
|
||||||
|
key,
|
||||||
|
ReflectGetOwnPropertyDescriptor(src, key));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const makeSafe = (unsafe, safe) => {
|
||||||
|
if (SymbolIterator in unsafe.prototype) {
|
||||||
|
const dummy = new unsafe();
|
||||||
|
let next; // We can reuse the same `next` method.
|
||||||
|
|
||||||
|
ArrayPrototypeForEach(ReflectOwnKeys(unsafe.prototype), (key) => {
|
||||||
|
if (!ReflectGetOwnPropertyDescriptor(safe.prototype, key)) {
|
||||||
|
const desc = ReflectGetOwnPropertyDescriptor(unsafe.prototype, key);
|
||||||
|
if (
|
||||||
|
typeof desc.value === 'function' &&
|
||||||
|
desc.value.length === 0 &&
|
||||||
|
SymbolIterator in (FunctionPrototypeCall(desc.value, dummy) ?? {})
|
||||||
|
) {
|
||||||
|
const createIterator = uncurryThis(desc.value);
|
||||||
|
next = next ?? uncurryThis(createIterator(dummy).next);
|
||||||
|
const SafeIterator = createSafeIterator(createIterator, next);
|
||||||
|
desc.value = function() {
|
||||||
|
return new SafeIterator(this);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
ReflectDefineProperty(safe.prototype, key, desc);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
copyProps(unsafe.prototype, safe.prototype);
|
||||||
|
}
|
||||||
|
copyProps(unsafe, safe);
|
||||||
|
|
||||||
|
ObjectSetPrototypeOf(safe.prototype, null);
|
||||||
|
ObjectFreeze(safe.prototype);
|
||||||
|
ObjectFreeze(safe);
|
||||||
|
return safe;
|
||||||
|
};
|
||||||
|
primordials.makeSafe = makeSafe;
|
||||||
|
|
||||||
|
// Subclass the constructors because we need to use their prototype
|
||||||
|
// methods later.
|
||||||
|
// Defining the `constructor` is necessary here to avoid the default
|
||||||
|
// constructor which uses the user-mutable `%ArrayIteratorPrototype%.next`.
|
||||||
|
primordials.SafeMap = makeSafe(
|
||||||
|
Map,
|
||||||
|
class SafeMap extends Map {
|
||||||
|
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
|
||||||
|
}
|
||||||
|
);
|
||||||
|
primordials.SafeWeakMap = makeSafe(
|
||||||
|
WeakMap,
|
||||||
|
class SafeWeakMap extends WeakMap {
|
||||||
|
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
|
||||||
|
}
|
||||||
|
);
|
||||||
|
primordials.SafeSet = makeSafe(
|
||||||
|
Set,
|
||||||
|
class SafeSet extends Set {
|
||||||
|
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
|
||||||
|
}
|
||||||
|
);
|
||||||
|
primordials.SafeWeakSet = makeSafe(
|
||||||
|
WeakSet,
|
||||||
|
class SafeWeakSet extends WeakSet {
|
||||||
|
constructor(i) { super(i); } // eslint-disable-line no-useless-constructor
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
ObjectSetPrototypeOf(primordials, null);
|
||||||
|
ObjectFreeze(primordials);
|
||||||
|
|
||||||
|
module.exports = primordials;
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// This is a placeholder for util.js in node.js land.
|
||||||
|
|
||||||
|
const {
|
||||||
|
ObjectCreate,
|
||||||
|
ObjectFreeze,
|
||||||
|
} = require('./primordials');
|
||||||
|
|
||||||
|
const kEmptyObject = ObjectFreeze(ObjectCreate(null));
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
kEmptyObject,
|
||||||
|
};
|
||||||
+89
@@ -0,0 +1,89 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// This file is a proxy of the original file located at:
|
||||||
|
// https://github.com/nodejs/node/blob/main/lib/internal/validators.js
|
||||||
|
// Every addition or modification to this file must be evaluated
|
||||||
|
// during the PR review.
|
||||||
|
|
||||||
|
const {
|
||||||
|
ArrayIsArray,
|
||||||
|
ArrayPrototypeIncludes,
|
||||||
|
ArrayPrototypeJoin,
|
||||||
|
} = require('./primordials');
|
||||||
|
|
||||||
|
const {
|
||||||
|
codes: {
|
||||||
|
ERR_INVALID_ARG_TYPE
|
||||||
|
}
|
||||||
|
} = require('./errors');
|
||||||
|
|
||||||
|
function validateString(value, name) {
|
||||||
|
if (typeof value !== 'string') {
|
||||||
|
throw new ERR_INVALID_ARG_TYPE(name, 'String', value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateUnion(value, name, union) {
|
||||||
|
if (!ArrayPrototypeIncludes(union, value)) {
|
||||||
|
throw new ERR_INVALID_ARG_TYPE(name, `('${ArrayPrototypeJoin(union, '|')}')`, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateBoolean(value, name) {
|
||||||
|
if (typeof value !== 'boolean') {
|
||||||
|
throw new ERR_INVALID_ARG_TYPE(name, 'Boolean', value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateArray(value, name) {
|
||||||
|
if (!ArrayIsArray(value)) {
|
||||||
|
throw new ERR_INVALID_ARG_TYPE(name, 'Array', value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateStringArray(value, name) {
|
||||||
|
validateArray(value, name);
|
||||||
|
for (let i = 0; i < value.length; i++) {
|
||||||
|
validateString(value[i], `${name}[${i}]`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateBooleanArray(value, name) {
|
||||||
|
validateArray(value, name);
|
||||||
|
for (let i = 0; i < value.length; i++) {
|
||||||
|
validateBoolean(value[i], `${name}[${i}]`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {unknown} value
|
||||||
|
* @param {string} name
|
||||||
|
* @param {{
|
||||||
|
* allowArray?: boolean,
|
||||||
|
* allowFunction?: boolean,
|
||||||
|
* nullable?: boolean
|
||||||
|
* }} [options]
|
||||||
|
*/
|
||||||
|
function validateObject(value, name, options) {
|
||||||
|
const useDefaultOptions = options == null;
|
||||||
|
const allowArray = useDefaultOptions ? false : options.allowArray;
|
||||||
|
const allowFunction = useDefaultOptions ? false : options.allowFunction;
|
||||||
|
const nullable = useDefaultOptions ? false : options.nullable;
|
||||||
|
if ((!nullable && value === null) ||
|
||||||
|
(!allowArray && ArrayIsArray(value)) ||
|
||||||
|
(typeof value !== 'object' && (
|
||||||
|
!allowFunction || typeof value !== 'function'
|
||||||
|
))) {
|
||||||
|
throw new ERR_INVALID_ARG_TYPE(name, 'Object', value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
validateArray,
|
||||||
|
validateObject,
|
||||||
|
validateString,
|
||||||
|
validateStringArray,
|
||||||
|
validateUnion,
|
||||||
|
validateBoolean,
|
||||||
|
validateBooleanArray,
|
||||||
|
};
|
||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
{
|
||||||
|
"name": "@pkgjs/parseargs",
|
||||||
|
"version": "0.11.0",
|
||||||
|
"description": "Polyfill of future proposal for `util.parseArgs()`",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=14"
|
||||||
|
},
|
||||||
|
"main": "index.js",
|
||||||
|
"exports": {
|
||||||
|
".": "./index.js",
|
||||||
|
"./package.json": "./package.json"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"coverage": "c8 --check-coverage tape 'test/*.js'",
|
||||||
|
"test": "c8 tape 'test/*.js'",
|
||||||
|
"posttest": "eslint .",
|
||||||
|
"fix": "npm run posttest -- --fix"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git@github.com:pkgjs/parseargs.git"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "MIT",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/pkgjs/parseargs/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/pkgjs/parseargs#readme",
|
||||||
|
"devDependencies": {
|
||||||
|
"c8": "^7.10.0",
|
||||||
|
"eslint": "^8.2.0",
|
||||||
|
"eslint-plugin-node-core": "iansu/eslint-plugin-node-core",
|
||||||
|
"tape": "^5.2.2"
|
||||||
|
}
|
||||||
|
}
|
||||||
+198
@@ -0,0 +1,198 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const {
|
||||||
|
ArrayPrototypeFind,
|
||||||
|
ObjectEntries,
|
||||||
|
ObjectPrototypeHasOwnProperty: ObjectHasOwn,
|
||||||
|
StringPrototypeCharAt,
|
||||||
|
StringPrototypeIncludes,
|
||||||
|
StringPrototypeStartsWith,
|
||||||
|
} = require('./internal/primordials');
|
||||||
|
|
||||||
|
const {
|
||||||
|
validateObject,
|
||||||
|
} = require('./internal/validators');
|
||||||
|
|
||||||
|
// These are internal utilities to make the parsing logic easier to read, and
|
||||||
|
// add lots of detail for the curious. They are in a separate file to allow
|
||||||
|
// unit testing, although that is not essential (this could be rolled into
|
||||||
|
// main file and just tested implicitly via API).
|
||||||
|
//
|
||||||
|
// These routines are for internal use, not for export to client.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the named property, but only if it is an own property.
|
||||||
|
*/
|
||||||
|
function objectGetOwn(obj, prop) {
|
||||||
|
if (ObjectHasOwn(obj, prop))
|
||||||
|
return obj[prop];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the named options property, but only if it is an own property.
|
||||||
|
*/
|
||||||
|
function optionsGetOwn(options, longOption, prop) {
|
||||||
|
if (ObjectHasOwn(options, longOption))
|
||||||
|
return objectGetOwn(options[longOption], prop);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if the argument may be used as an option value.
|
||||||
|
* @example
|
||||||
|
* isOptionValue('V') // returns true
|
||||||
|
* isOptionValue('-v') // returns true (greedy)
|
||||||
|
* isOptionValue('--foo') // returns true (greedy)
|
||||||
|
* isOptionValue(undefined) // returns false
|
||||||
|
*/
|
||||||
|
function isOptionValue(value) {
|
||||||
|
if (value == null) return false;
|
||||||
|
|
||||||
|
// Open Group Utility Conventions are that an option-argument
|
||||||
|
// is the argument after the option, and may start with a dash.
|
||||||
|
return true; // greedy!
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Detect whether there is possible confusion and user may have omitted
|
||||||
|
* the option argument, like `--port --verbose` when `port` of type:string.
|
||||||
|
* In strict mode we throw errors if value is option-like.
|
||||||
|
*/
|
||||||
|
function isOptionLikeValue(value) {
|
||||||
|
if (value == null) return false;
|
||||||
|
|
||||||
|
return value.length > 1 && StringPrototypeCharAt(value, 0) === '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if `arg` is just a short option.
|
||||||
|
* @example '-f'
|
||||||
|
*/
|
||||||
|
function isLoneShortOption(arg) {
|
||||||
|
return arg.length === 2 &&
|
||||||
|
StringPrototypeCharAt(arg, 0) === '-' &&
|
||||||
|
StringPrototypeCharAt(arg, 1) !== '-';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if `arg` is a lone long option.
|
||||||
|
* @example
|
||||||
|
* isLoneLongOption('a') // returns false
|
||||||
|
* isLoneLongOption('-a') // returns false
|
||||||
|
* isLoneLongOption('--foo') // returns true
|
||||||
|
* isLoneLongOption('--foo=bar') // returns false
|
||||||
|
*/
|
||||||
|
function isLoneLongOption(arg) {
|
||||||
|
return arg.length > 2 &&
|
||||||
|
StringPrototypeStartsWith(arg, '--') &&
|
||||||
|
!StringPrototypeIncludes(arg, '=', 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if `arg` is a long option and value in the same argument.
|
||||||
|
* @example
|
||||||
|
* isLongOptionAndValue('--foo') // returns false
|
||||||
|
* isLongOptionAndValue('--foo=bar') // returns true
|
||||||
|
*/
|
||||||
|
function isLongOptionAndValue(arg) {
|
||||||
|
return arg.length > 2 &&
|
||||||
|
StringPrototypeStartsWith(arg, '--') &&
|
||||||
|
StringPrototypeIncludes(arg, '=', 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines if `arg` is a short option group.
|
||||||
|
*
|
||||||
|
* See Guideline 5 of the [Open Group Utility Conventions](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html).
|
||||||
|
* One or more options without option-arguments, followed by at most one
|
||||||
|
* option that takes an option-argument, should be accepted when grouped
|
||||||
|
* behind one '-' delimiter.
|
||||||
|
* @example
|
||||||
|
* isShortOptionGroup('-a', {}) // returns false
|
||||||
|
* isShortOptionGroup('-ab', {}) // returns true
|
||||||
|
* // -fb is an option and a value, not a short option group
|
||||||
|
* isShortOptionGroup('-fb', {
|
||||||
|
* options: { f: { type: 'string' } }
|
||||||
|
* }) // returns false
|
||||||
|
* isShortOptionGroup('-bf', {
|
||||||
|
* options: { f: { type: 'string' } }
|
||||||
|
* }) // returns true
|
||||||
|
* // -bfb is an edge case, return true and caller sorts it out
|
||||||
|
* isShortOptionGroup('-bfb', {
|
||||||
|
* options: { f: { type: 'string' } }
|
||||||
|
* }) // returns true
|
||||||
|
*/
|
||||||
|
function isShortOptionGroup(arg, options) {
|
||||||
|
if (arg.length <= 2) return false;
|
||||||
|
if (StringPrototypeCharAt(arg, 0) !== '-') return false;
|
||||||
|
if (StringPrototypeCharAt(arg, 1) === '-') return false;
|
||||||
|
|
||||||
|
const firstShort = StringPrototypeCharAt(arg, 1);
|
||||||
|
const longOption = findLongOptionForShort(firstShort, options);
|
||||||
|
return optionsGetOwn(options, longOption, 'type') !== 'string';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determine if arg is a short string option followed by its value.
|
||||||
|
* @example
|
||||||
|
* isShortOptionAndValue('-a', {}); // returns false
|
||||||
|
* isShortOptionAndValue('-ab', {}); // returns false
|
||||||
|
* isShortOptionAndValue('-fFILE', {
|
||||||
|
* options: { foo: { short: 'f', type: 'string' }}
|
||||||
|
* }) // returns true
|
||||||
|
*/
|
||||||
|
function isShortOptionAndValue(arg, options) {
|
||||||
|
validateObject(options, 'options');
|
||||||
|
|
||||||
|
if (arg.length <= 2) return false;
|
||||||
|
if (StringPrototypeCharAt(arg, 0) !== '-') return false;
|
||||||
|
if (StringPrototypeCharAt(arg, 1) === '-') return false;
|
||||||
|
|
||||||
|
const shortOption = StringPrototypeCharAt(arg, 1);
|
||||||
|
const longOption = findLongOptionForShort(shortOption, options);
|
||||||
|
return optionsGetOwn(options, longOption, 'type') === 'string';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find the long option associated with a short option. Looks for a configured
|
||||||
|
* `short` and returns the short option itself if a long option is not found.
|
||||||
|
* @example
|
||||||
|
* findLongOptionForShort('a', {}) // returns 'a'
|
||||||
|
* findLongOptionForShort('b', {
|
||||||
|
* options: { bar: { short: 'b' } }
|
||||||
|
* }) // returns 'bar'
|
||||||
|
*/
|
||||||
|
function findLongOptionForShort(shortOption, options) {
|
||||||
|
validateObject(options, 'options');
|
||||||
|
const longOptionEntry = ArrayPrototypeFind(
|
||||||
|
ObjectEntries(options),
|
||||||
|
({ 1: optionConfig }) => objectGetOwn(optionConfig, 'short') === shortOption
|
||||||
|
);
|
||||||
|
return longOptionEntry?.[0] ?? shortOption;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the given option includes a default value
|
||||||
|
* and that option has not been set by the input args.
|
||||||
|
*
|
||||||
|
* @param {string} longOption - long option name e.g. 'foo'
|
||||||
|
* @param {object} optionConfig - the option configuration properties
|
||||||
|
* @param {object} values - option values returned in `values` by parseArgs
|
||||||
|
*/
|
||||||
|
function useDefaultValueOption(longOption, optionConfig, values) {
|
||||||
|
return objectGetOwn(optionConfig, 'default') !== undefined &&
|
||||||
|
values[longOption] === undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
findLongOptionForShort,
|
||||||
|
isLoneLongOption,
|
||||||
|
isLoneShortOption,
|
||||||
|
isLongOptionAndValue,
|
||||||
|
isOptionValue,
|
||||||
|
isOptionLikeValue,
|
||||||
|
isShortOptionAndValue,
|
||||||
|
isShortOptionGroup,
|
||||||
|
useDefaultValueOption,
|
||||||
|
objectGetOwn,
|
||||||
|
optionsGetOwn,
|
||||||
|
};
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _applyDecoratedDescriptor;
|
||||||
|
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
|
||||||
|
var desc1 = {};
|
||||||
|
Object['ke' + 'ys'](descriptor).forEach(function(key) {
|
||||||
|
desc1[key] = descriptor[key];
|
||||||
|
});
|
||||||
|
desc1.enumerable = !!desc1.enumerable;
|
||||||
|
desc1.configurable = !!desc1.configurable;
|
||||||
|
if ('value' in desc1 || desc1.initializer) {
|
||||||
|
desc1.writable = true;
|
||||||
|
}
|
||||||
|
desc1 = decorators.slice().reverse().reduce(function(desc, decorator) {
|
||||||
|
return decorator ? decorator(target, property, desc) || desc : desc;
|
||||||
|
}, desc1);
|
||||||
|
var hasAccessor = Object.prototype.hasOwnProperty.call(desc1, 'get') || Object.prototype.hasOwnProperty.call(desc1, 'set');
|
||||||
|
if (context && desc1.initializer !== void 0 && !hasAccessor) {
|
||||||
|
desc1.value = desc1.initializer ? desc1.initializer.call(context) : void 0;
|
||||||
|
desc1.initializer = undefined;
|
||||||
|
}
|
||||||
|
if (hasAccessor) {
|
||||||
|
delete desc1.writable;
|
||||||
|
delete desc1.initializer;
|
||||||
|
delete desc1.value;
|
||||||
|
}
|
||||||
|
if (desc1.initializer === void 0) {
|
||||||
|
Object['define' + 'Property'](target, property, desc1);
|
||||||
|
desc1 = null;
|
||||||
|
}
|
||||||
|
return desc1;
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _arrayLikeToArray;
|
||||||
|
function _arrayLikeToArray(arr, len) {
|
||||||
|
if (len == null || len > arr.length) len = arr.length;
|
||||||
|
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
||||||
|
return arr2;
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _arrayWithHoles;
|
||||||
|
function _arrayWithHoles(arr) {
|
||||||
|
if (Array.isArray(arr)) return arr;
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _arrayWithoutHoles;
|
||||||
|
var _arrayLikeToArray = _interopRequireDefault(require("./_array_like_to_array"));
|
||||||
|
function _arrayWithoutHoles(arr) {
|
||||||
|
if (Array.isArray(arr)) return (0, _arrayLikeToArray).default(arr);
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _assertThisInitialized;
|
||||||
|
function _assertThisInitialized(self) {
|
||||||
|
if (self === void 0) {
|
||||||
|
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
+92
@@ -0,0 +1,92 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = AsyncGenerator;
|
||||||
|
var _awaitValue = _interopRequireDefault(require("./_await_value"));
|
||||||
|
function AsyncGenerator(gen) {
|
||||||
|
var front, back;
|
||||||
|
function send(key, arg) {
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
var request = {
|
||||||
|
key: key,
|
||||||
|
arg: arg,
|
||||||
|
resolve: resolve,
|
||||||
|
reject: reject,
|
||||||
|
next: null
|
||||||
|
};
|
||||||
|
if (back) {
|
||||||
|
back = back.next = request;
|
||||||
|
} else {
|
||||||
|
front = back = request;
|
||||||
|
resume(key, arg);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function resume(key, arg1) {
|
||||||
|
try {
|
||||||
|
var result = gen[key](arg1);
|
||||||
|
var value = result.value;
|
||||||
|
var wrappedAwait = value instanceof _awaitValue.default;
|
||||||
|
Promise.resolve(wrappedAwait ? value.wrapped : value).then(function(arg) {
|
||||||
|
if (wrappedAwait) {
|
||||||
|
resume("next", arg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
settle(result.done ? "return" : "normal", arg);
|
||||||
|
}, function(err) {
|
||||||
|
resume("throw", err);
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
settle("throw", err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function settle(type, value) {
|
||||||
|
switch(type){
|
||||||
|
case "return":
|
||||||
|
front.resolve({
|
||||||
|
value: value,
|
||||||
|
done: true
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case "throw":
|
||||||
|
front.reject(value);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
front.resolve({
|
||||||
|
value: value,
|
||||||
|
done: false
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
front = front.next;
|
||||||
|
if (front) {
|
||||||
|
resume(front.key, front.arg);
|
||||||
|
} else {
|
||||||
|
back = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this._invoke = send;
|
||||||
|
if (typeof gen.return !== "function") {
|
||||||
|
this.return = undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (typeof Symbol === "function" && Symbol.asyncIterator) {
|
||||||
|
AsyncGenerator.prototype[Symbol.asyncIterator] = function() {
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
AsyncGenerator.prototype.next = function(arg) {
|
||||||
|
return this._invoke("next", arg);
|
||||||
|
};
|
||||||
|
AsyncGenerator.prototype.throw = function(arg) {
|
||||||
|
return this._invoke("throw", arg);
|
||||||
|
};
|
||||||
|
AsyncGenerator.prototype.return = function(arg) {
|
||||||
|
return this._invoke("return", arg);
|
||||||
|
};
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _asyncGeneratorDelegate;
|
||||||
|
function _asyncGeneratorDelegate(inner, awaitWrap) {
|
||||||
|
var iter = {}, waiting = false;
|
||||||
|
function pump(key, value) {
|
||||||
|
waiting = true;
|
||||||
|
value = new Promise(function(resolve) {
|
||||||
|
resolve(inner[key](value));
|
||||||
|
});
|
||||||
|
return {
|
||||||
|
done: false,
|
||||||
|
value: awaitWrap(value)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (typeof Symbol === "function" && Symbol.iterator) {
|
||||||
|
iter[Symbol.iterator] = function() {
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
iter.next = function(value) {
|
||||||
|
if (waiting) {
|
||||||
|
waiting = false;
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return pump("next", value);
|
||||||
|
};
|
||||||
|
if (typeof inner.throw === "function") {
|
||||||
|
iter.throw = function(value) {
|
||||||
|
if (waiting) {
|
||||||
|
waiting = false;
|
||||||
|
throw value;
|
||||||
|
}
|
||||||
|
return pump("throw", value);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (typeof inner.return === "function") {
|
||||||
|
iter.return = function(value) {
|
||||||
|
return pump("return", value);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return iter;
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _asyncIterator;
|
||||||
|
function _asyncIterator(iterable) {
|
||||||
|
var method;
|
||||||
|
if (typeof Symbol === "function") {
|
||||||
|
if (Symbol.asyncIterator) {
|
||||||
|
method = iterable[Symbol.asyncIterator];
|
||||||
|
if (method != null) return method.call(iterable);
|
||||||
|
}
|
||||||
|
if (Symbol.iterator) {
|
||||||
|
method = iterable[Symbol.iterator];
|
||||||
|
if (method != null) return method.call(iterable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new TypeError("Object is not async iterable");
|
||||||
|
}
|
||||||
+34
@@ -0,0 +1,34 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _asyncToGenerator;
|
||||||
|
function _asyncToGenerator(fn) {
|
||||||
|
return function() {
|
||||||
|
var self = this, args = arguments;
|
||||||
|
return new Promise(function(resolve, reject) {
|
||||||
|
var gen = fn.apply(self, args);
|
||||||
|
function _next(value) {
|
||||||
|
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
||||||
|
}
|
||||||
|
function _throw(err) {
|
||||||
|
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
||||||
|
}
|
||||||
|
_next(undefined);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
||||||
|
try {
|
||||||
|
var info = gen[key](arg);
|
||||||
|
var value = info.value;
|
||||||
|
} catch (error) {
|
||||||
|
reject(error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (info.done) {
|
||||||
|
resolve(value);
|
||||||
|
} else {
|
||||||
|
Promise.resolve(value).then(_next, _throw);
|
||||||
|
}
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _awaitAsyncGenerator;
|
||||||
|
var _awaitValue = _interopRequireDefault(require("./_await_value"));
|
||||||
|
function _awaitAsyncGenerator(value) {
|
||||||
|
return new _awaitValue.default(value);
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _AwaitValue;
|
||||||
|
function _AwaitValue(value) {
|
||||||
|
this.wrapped = value;
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _checkPrivateRedeclaration;
|
||||||
|
function _checkPrivateRedeclaration(obj, privateCollection) {
|
||||||
|
if (privateCollection.has(obj)) {
|
||||||
|
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classApplyDescriptorDestructureSet;
|
||||||
|
function _classApplyDescriptorDestructureSet(receiver, descriptor) {
|
||||||
|
if (descriptor.set) {
|
||||||
|
if (!("__destrObj" in descriptor)) {
|
||||||
|
descriptor.__destrObj = {
|
||||||
|
set value (v){
|
||||||
|
descriptor.set.call(receiver, v);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return descriptor.__destrObj;
|
||||||
|
} else {
|
||||||
|
if (!descriptor.writable) {
|
||||||
|
// This should only throw in strict mode, but class bodies are
|
||||||
|
// always strict and private fields can only be used inside
|
||||||
|
// class bodies.
|
||||||
|
throw new TypeError("attempted to set read only private field");
|
||||||
|
}
|
||||||
|
return descriptor;
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classApplyDescriptorGet;
|
||||||
|
function _classApplyDescriptorGet(receiver, descriptor) {
|
||||||
|
if (descriptor.get) {
|
||||||
|
return descriptor.get.call(receiver);
|
||||||
|
}
|
||||||
|
return descriptor.value;
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classApplyDescriptorSet;
|
||||||
|
function _classApplyDescriptorSet(receiver, descriptor, value) {
|
||||||
|
if (descriptor.set) {
|
||||||
|
descriptor.set.call(receiver, value);
|
||||||
|
} else {
|
||||||
|
if (!descriptor.writable) {
|
||||||
|
// This should only throw in strict mode, but class bodies are
|
||||||
|
// always strict and private fields can only be used inside
|
||||||
|
// class bodies.
|
||||||
|
throw new TypeError("attempted to set read only private field");
|
||||||
|
}
|
||||||
|
descriptor.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classApplyDescriptorUpdate;
|
||||||
|
function _classApplyDescriptorUpdate(receiver, descriptor) {
|
||||||
|
if (descriptor.set) {
|
||||||
|
if (!("__destrWrapper" in descriptor)) {
|
||||||
|
descriptor.__destrWrapper = {
|
||||||
|
set value (v){
|
||||||
|
descriptor.set.call(receiver, v);
|
||||||
|
},
|
||||||
|
get value () {
|
||||||
|
return descriptor.get.call(receiver);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return descriptor.__destrWrapper;
|
||||||
|
} else {
|
||||||
|
if (!descriptor.writable) {
|
||||||
|
// This should only throw in strict mode, but class bodies are
|
||||||
|
// always strict and private fields can only be used inside
|
||||||
|
// class bodies.
|
||||||
|
throw new TypeError("attempted to set read only private field");
|
||||||
|
}
|
||||||
|
return descriptor;
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classCallCheck;
|
||||||
|
function _classCallCheck(instance, Constructor) {
|
||||||
|
if (!(instance instanceof Constructor)) {
|
||||||
|
throw new TypeError("Cannot call a class as a function");
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classCheckPrivateStaticAccess;
|
||||||
|
function _classCheckPrivateStaticAccess(receiver, classConstructor) {
|
||||||
|
if (receiver !== classConstructor) {
|
||||||
|
throw new TypeError("Private static access of wrong provenance");
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
Vendored
+10
@@ -0,0 +1,10 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classCheckPrivateStaticFieldDescriptor;
|
||||||
|
function _classCheckPrivateStaticFieldDescriptor(descriptor, action) {
|
||||||
|
if (descriptor === undefined) {
|
||||||
|
throw new TypeError("attempted to " + action + " private static field before its declaration");
|
||||||
|
}
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classExtractFieldDescriptor;
|
||||||
|
function _classExtractFieldDescriptor(receiver, privateMap, action) {
|
||||||
|
if (!privateMap.has(receiver)) {
|
||||||
|
throw new TypeError("attempted to " + action + " private field on non-instance");
|
||||||
|
}
|
||||||
|
return privateMap.get(receiver);
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classNameTDZError;
|
||||||
|
function _classNameTDZError(name) {
|
||||||
|
throw new Error("Class \"" + name + "\" cannot be referenced in computed property keys.");
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classPrivateFieldDestructureSet;
|
||||||
|
var _classExtractFieldDescriptor = _interopRequireDefault(require("./_class_extract_field_descriptor"));
|
||||||
|
var _classApplyDescriptorDestructure = _interopRequireDefault(require("./_class_apply_descriptor_destructure"));
|
||||||
|
function _classPrivateFieldDestructureSet(receiver, privateMap) {
|
||||||
|
var descriptor = (0, _classExtractFieldDescriptor).default(receiver, privateMap, "set");
|
||||||
|
return (0, _classApplyDescriptorDestructure).default(receiver, descriptor);
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classPrivateFieldGet;
|
||||||
|
var _classExtractFieldDescriptor = _interopRequireDefault(require("./_class_extract_field_descriptor"));
|
||||||
|
var _classApplyDescriptorGet = _interopRequireDefault(require("./_class_apply_descriptor_get"));
|
||||||
|
function _classPrivateFieldGet(receiver, privateMap) {
|
||||||
|
var descriptor = (0, _classExtractFieldDescriptor).default(receiver, privateMap, "get");
|
||||||
|
return (0, _classApplyDescriptorGet).default(receiver, descriptor);
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classPrivateFieldInit;
|
||||||
|
var _checkPrivateRedeclaration = _interopRequireDefault(require("./_check_private_redeclaration"));
|
||||||
|
function _classPrivateFieldInit(obj, privateMap, value) {
|
||||||
|
(0, _checkPrivateRedeclaration).default(obj, privateMap);
|
||||||
|
privateMap.set(obj, value);
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classPrivateFieldBase;
|
||||||
|
function _classPrivateFieldBase(receiver, privateKey) {
|
||||||
|
if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
|
||||||
|
throw new TypeError("attempted to use private field on non-instance");
|
||||||
|
}
|
||||||
|
return receiver;
|
||||||
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classPrivateFieldLooseKey;
|
||||||
|
function _classPrivateFieldLooseKey(name) {
|
||||||
|
return "__private_" + id++ + "_" + name;
|
||||||
|
}
|
||||||
|
var id = 0;
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classPrivateFieldSet;
|
||||||
|
var _classExtractFieldDescriptor = _interopRequireDefault(require("./_class_extract_field_descriptor"));
|
||||||
|
var _classApplyDescriptorSet = _interopRequireDefault(require("./_class_apply_descriptor_set"));
|
||||||
|
function _classPrivateFieldSet(receiver, privateMap, value) {
|
||||||
|
var descriptor = (0, _classExtractFieldDescriptor).default(receiver, privateMap, "set");
|
||||||
|
(0, _classApplyDescriptorSet).default(receiver, descriptor, value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classPrivateFieldUpdate;
|
||||||
|
var _classExtractFieldDescriptor = _interopRequireDefault(require("./_class_extract_field_descriptor"));
|
||||||
|
var _classApplyDescriptorUpdate = _interopRequireDefault(require("./_class_apply_descriptor_update"));
|
||||||
|
function _classPrivateFieldUpdate(receiver, privateMap) {
|
||||||
|
var descriptor = (0, _classExtractFieldDescriptor).default(receiver, privateMap, "update");
|
||||||
|
return (0, _classApplyDescriptorUpdate).default(receiver, descriptor);
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classPrivateMethodGet;
|
||||||
|
function _classPrivateMethodGet(receiver, privateSet, fn) {
|
||||||
|
if (!privateSet.has(receiver)) {
|
||||||
|
throw new TypeError("attempted to get private field on non-instance");
|
||||||
|
}
|
||||||
|
return fn;
|
||||||
|
}
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classPrivateMethodInit;
|
||||||
|
var _checkPrivateRedeclaration = _interopRequireDefault(require("./_check_private_redeclaration"));
|
||||||
|
function _classPrivateMethodInit(obj, privateSet) {
|
||||||
|
(0, _checkPrivateRedeclaration).default(obj, privateSet);
|
||||||
|
privateSet.add(obj);
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classPrivateMethodSet;
|
||||||
|
function _classPrivateMethodSet() {
|
||||||
|
throw new TypeError("attempted to reassign private method");
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classStaticPrivateFieldDestructureSet;
|
||||||
|
var _classCheckPrivateStaticAccess = _interopRequireDefault(require("./_class_check_private_static_access"));
|
||||||
|
var _classApplyDescriptorDestructure = _interopRequireDefault(require("./_class_apply_descriptor_destructure"));
|
||||||
|
function _classStaticPrivateFieldDestructureSet(receiver, classConstructor, descriptor) {
|
||||||
|
(0, _classCheckPrivateStaticAccess).default(receiver, classConstructor);
|
||||||
|
(0, _classCheckPrivateStaticAccess).default(descriptor, "set");
|
||||||
|
return (0, _classApplyDescriptorDestructure).default(receiver, descriptor);
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classStaticPrivateFieldSpecGet;
|
||||||
|
var _classCheckPrivateStaticAccess = _interopRequireDefault(require("./_class_check_private_static_access"));
|
||||||
|
var _classApplyDescriptorGet = _interopRequireDefault(require("./_class_apply_descriptor_get"));
|
||||||
|
function _classStaticPrivateFieldSpecGet(receiver, classConstructor, descriptor) {
|
||||||
|
(0, _classCheckPrivateStaticAccess).default(receiver, classConstructor);
|
||||||
|
(0, _classCheckPrivateStaticAccess).default(descriptor, "get");
|
||||||
|
return (0, _classApplyDescriptorGet).default(receiver, descriptor);
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classStaticPrivateFieldSpecSet;
|
||||||
|
var _classCheckPrivateStaticAccess = _interopRequireDefault(require("./_class_check_private_static_access"));
|
||||||
|
var _classApplyDescriptorSet = _interopRequireDefault(require("./_class_apply_descriptor_set"));
|
||||||
|
function _classStaticPrivateFieldSpecSet(receiver, classConstructor, descriptor, value) {
|
||||||
|
(0, _classCheckPrivateStaticAccess).default(receiver, classConstructor);
|
||||||
|
(0, _classCheckPrivateStaticAccess).default(descriptor, "set");
|
||||||
|
(0, _classApplyDescriptorSet).default(receiver, descriptor, value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _classStaticPrivateFieldUpdate;
|
||||||
|
var _classCheckPrivateStaticAccess = _interopRequireDefault(require("./_class_check_private_static_access"));
|
||||||
|
var _classApplyDescriptorUpdate = _interopRequireDefault(require("./_class_apply_descriptor_update"));
|
||||||
|
function _classStaticPrivateFieldUpdate(receiver, classConstructor, descriptor) {
|
||||||
|
(0, _classCheckPrivateStaticAccess).default(receiver, classConstructor);
|
||||||
|
(0, _classCheckPrivateStaticAccess).default(descriptor, "update");
|
||||||
|
return (0, _classApplyDescriptorUpdate).default(receiver, descriptor);
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _construct;
|
||||||
|
var _setPrototypeOf = _interopRequireDefault(require("./_set_prototype_of"));
|
||||||
|
function _construct(Parent, args, Class) {
|
||||||
|
return construct.apply(null, arguments);
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function isNativeReflectConstruct() {
|
||||||
|
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
||||||
|
if (Reflect.construct.sham) return false;
|
||||||
|
if (typeof Proxy === "function") return true;
|
||||||
|
try {
|
||||||
|
Date.prototype.toString.call(Reflect.construct(Date, [], function() {}));
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function construct(Parent1, args1, Class1) {
|
||||||
|
if (isNativeReflectConstruct()) {
|
||||||
|
construct = Reflect.construct;
|
||||||
|
} else {
|
||||||
|
construct = function construct(Parent, args, Class) {
|
||||||
|
var a = [
|
||||||
|
null
|
||||||
|
];
|
||||||
|
a.push.apply(a, args);
|
||||||
|
var Constructor = Function.bind.apply(Parent, a);
|
||||||
|
var instance = new Constructor();
|
||||||
|
if (Class) (0, _setPrototypeOf).default(instance, Class.prototype);
|
||||||
|
return instance;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return construct.apply(null, arguments);
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _createClass;
|
||||||
|
function _createClass(Constructor, protoProps, staticProps) {
|
||||||
|
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
||||||
|
if (staticProps) _defineProperties(Constructor, staticProps);
|
||||||
|
return Constructor;
|
||||||
|
}
|
||||||
|
function _defineProperties(target, props) {
|
||||||
|
for(var i = 0; i < props.length; i++){
|
||||||
|
var descriptor = props[i];
|
||||||
|
descriptor.enumerable = descriptor.enumerable || false;
|
||||||
|
descriptor.configurable = true;
|
||||||
|
if ("value" in descriptor) descriptor.writable = true;
|
||||||
|
Object.defineProperty(target, descriptor.key, descriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
+26
@@ -0,0 +1,26 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _createSuper;
|
||||||
|
var _isNativeReflectConstruct = _interopRequireDefault(require("./_is_native_reflect_construct"));
|
||||||
|
var _getPrototypeOf = _interopRequireDefault(require("./_get_prototype_of"));
|
||||||
|
var _possibleConstructorReturn = _interopRequireDefault(require("./_possible_constructor_return"));
|
||||||
|
function _createSuper(Derived) {
|
||||||
|
var hasNativeReflectConstruct = (0, _isNativeReflectConstruct).default();
|
||||||
|
return function _createSuperInternal() {
|
||||||
|
var Super = (0, _getPrototypeOf).default(Derived), result;
|
||||||
|
if (hasNativeReflectConstruct) {
|
||||||
|
var NewTarget = (0, _getPrototypeOf).default(this).constructor;
|
||||||
|
result = Reflect.construct(Super, arguments, NewTarget);
|
||||||
|
} else {
|
||||||
|
result = Super.apply(this, arguments);
|
||||||
|
}
|
||||||
|
return (0, _possibleConstructorReturn).default(this, result);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
+347
@@ -0,0 +1,347 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _decorate;
|
||||||
|
var _toArray = _interopRequireDefault(require("./_to_array"));
|
||||||
|
var _toPropertyKey = _interopRequireDefault(require("./_to_property_key"));
|
||||||
|
function _decorate(decorators, factory, superClass) {
|
||||||
|
var r = factory(function initialize(O) {
|
||||||
|
_initializeInstanceElements(O, decorated.elements);
|
||||||
|
}, superClass);
|
||||||
|
var decorated = _decorateClass(_coalesceClassElements(r.d.map(_createElementDescriptor)), decorators);
|
||||||
|
_initializeClassElements(r.F, decorated.elements);
|
||||||
|
return _runClassFinishers(r.F, decorated.finishers);
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function _createElementDescriptor(def) {
|
||||||
|
var key = (0, _toPropertyKey).default(def.key);
|
||||||
|
var descriptor;
|
||||||
|
if (def.kind === "method") {
|
||||||
|
descriptor = {
|
||||||
|
value: def.value,
|
||||||
|
writable: true,
|
||||||
|
configurable: true,
|
||||||
|
enumerable: false
|
||||||
|
};
|
||||||
|
Object.defineProperty(def.value, "name", {
|
||||||
|
value: _typeof(key) === "symbol" ? "" : key,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
} else if (def.kind === "get") {
|
||||||
|
descriptor = {
|
||||||
|
get: def.value,
|
||||||
|
configurable: true,
|
||||||
|
enumerable: false
|
||||||
|
};
|
||||||
|
} else if (def.kind === "set") {
|
||||||
|
descriptor = {
|
||||||
|
set: def.value,
|
||||||
|
configurable: true,
|
||||||
|
enumerable: false
|
||||||
|
};
|
||||||
|
} else if (def.kind === "field") {
|
||||||
|
descriptor = {
|
||||||
|
configurable: true,
|
||||||
|
writable: true,
|
||||||
|
enumerable: true
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var element = {
|
||||||
|
kind: def.kind === "field" ? "field" : "method",
|
||||||
|
key: key,
|
||||||
|
placement: def.static ? "static" : def.kind === "field" ? "own" : "prototype",
|
||||||
|
descriptor: descriptor
|
||||||
|
};
|
||||||
|
if (def.decorators) element.decorators = def.decorators;
|
||||||
|
if (def.kind === "field") element.initializer = def.value;
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
function _coalesceGetterSetter(element, other) {
|
||||||
|
if (element.descriptor.get !== undefined) {
|
||||||
|
other.descriptor.get = element.descriptor.get;
|
||||||
|
} else {
|
||||||
|
other.descriptor.set = element.descriptor.set;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function _coalesceClassElements(elements) {
|
||||||
|
var newElements = [];
|
||||||
|
var isSameElement = function isSameElement(other) {
|
||||||
|
return other.kind === "method" && other.key === element.key && other.placement === element.placement;
|
||||||
|
};
|
||||||
|
for(var i = 0; i < elements.length; i++){
|
||||||
|
var element = elements[i];
|
||||||
|
var other1;
|
||||||
|
if (element.kind === "method" && (other1 = newElements.find(isSameElement))) {
|
||||||
|
if (_isDataDescriptor(element.descriptor) || _isDataDescriptor(other1.descriptor)) {
|
||||||
|
if (_hasDecorators(element) || _hasDecorators(other1)) {
|
||||||
|
throw new ReferenceError("Duplicated methods (" + element.key + ") can't be decorated.");
|
||||||
|
}
|
||||||
|
other1.descriptor = element.descriptor;
|
||||||
|
} else {
|
||||||
|
if (_hasDecorators(element)) {
|
||||||
|
if (_hasDecorators(other1)) {
|
||||||
|
throw new ReferenceError("Decorators can't be placed on different accessors with for " + "the same property (" + element.key + ").");
|
||||||
|
}
|
||||||
|
other1.decorators = element.decorators;
|
||||||
|
}
|
||||||
|
_coalesceGetterSetter(element, other1);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newElements.push(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return newElements;
|
||||||
|
}
|
||||||
|
function _hasDecorators(element) {
|
||||||
|
return element.decorators && element.decorators.length;
|
||||||
|
}
|
||||||
|
function _isDataDescriptor(desc) {
|
||||||
|
return desc !== undefined && !(desc.value === undefined && desc.writable === undefined);
|
||||||
|
}
|
||||||
|
function _initializeClassElements(F, elements) {
|
||||||
|
var proto = F.prototype;
|
||||||
|
[
|
||||||
|
"method",
|
||||||
|
"field"
|
||||||
|
].forEach(function(kind) {
|
||||||
|
elements.forEach(function(element) {
|
||||||
|
var placement = element.placement;
|
||||||
|
if (element.kind === kind && (placement === "static" || placement === "prototype")) {
|
||||||
|
var receiver = placement === "static" ? F : proto;
|
||||||
|
_defineClassElement(receiver, element);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function _initializeInstanceElements(O, elements) {
|
||||||
|
[
|
||||||
|
"method",
|
||||||
|
"field"
|
||||||
|
].forEach(function(kind) {
|
||||||
|
elements.forEach(function(element) {
|
||||||
|
if (element.kind === kind && element.placement === "own") {
|
||||||
|
_defineClassElement(O, element);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function _defineClassElement(receiver, element) {
|
||||||
|
var descriptor = element.descriptor;
|
||||||
|
if (element.kind === "field") {
|
||||||
|
var initializer = element.initializer;
|
||||||
|
descriptor = {
|
||||||
|
enumerable: descriptor.enumerable,
|
||||||
|
writable: descriptor.writable,
|
||||||
|
configurable: descriptor.configurable,
|
||||||
|
value: initializer === void 0 ? void 0 : initializer.call(receiver)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Object.defineProperty(receiver, element.key, descriptor);
|
||||||
|
}
|
||||||
|
function _decorateClass(elements, decorators) {
|
||||||
|
var newElements = [];
|
||||||
|
var finishers = [];
|
||||||
|
var placements = {
|
||||||
|
static: [],
|
||||||
|
prototype: [],
|
||||||
|
own: []
|
||||||
|
};
|
||||||
|
elements.forEach(function(element) {
|
||||||
|
_addElementPlacement(element, placements);
|
||||||
|
});
|
||||||
|
elements.forEach(function(element) {
|
||||||
|
if (!_hasDecorators(element)) return newElements.push(element);
|
||||||
|
var elementFinishersExtras = _decorateElement(element, placements);
|
||||||
|
newElements.push(elementFinishersExtras.element);
|
||||||
|
newElements.push.apply(newElements, elementFinishersExtras.extras);
|
||||||
|
finishers.push.apply(finishers, elementFinishersExtras.finishers);
|
||||||
|
});
|
||||||
|
if (!decorators) {
|
||||||
|
return {
|
||||||
|
elements: newElements,
|
||||||
|
finishers: finishers
|
||||||
|
};
|
||||||
|
}
|
||||||
|
var result = _decorateConstructor(newElements, decorators);
|
||||||
|
finishers.push.apply(finishers, result.finishers);
|
||||||
|
result.finishers = finishers;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
function _addElementPlacement(element, placements, silent) {
|
||||||
|
var keys = placements[element.placement];
|
||||||
|
if (!silent && keys.indexOf(element.key) !== -1) {
|
||||||
|
throw new TypeError("Duplicated element (" + element.key + ")");
|
||||||
|
}
|
||||||
|
keys.push(element.key);
|
||||||
|
}
|
||||||
|
function _decorateElement(element, placements) {
|
||||||
|
var extras = [];
|
||||||
|
var finishers = [];
|
||||||
|
for(var decorators = element.decorators, i = decorators.length - 1; i >= 0; i--){
|
||||||
|
var keys = placements[element.placement];
|
||||||
|
keys.splice(keys.indexOf(element.key), 1);
|
||||||
|
var elementObject = _fromElementDescriptor(element);
|
||||||
|
var elementFinisherExtras = _toElementFinisherExtras((0, decorators[i])(elementObject) || elementObject);
|
||||||
|
element = elementFinisherExtras.element;
|
||||||
|
_addElementPlacement(element, placements);
|
||||||
|
if (elementFinisherExtras.finisher) {
|
||||||
|
finishers.push(elementFinisherExtras.finisher);
|
||||||
|
}
|
||||||
|
var newExtras = elementFinisherExtras.extras;
|
||||||
|
if (newExtras) {
|
||||||
|
for(var j = 0; j < newExtras.length; j++){
|
||||||
|
_addElementPlacement(newExtras[j], placements);
|
||||||
|
}
|
||||||
|
extras.push.apply(extras, newExtras);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
element: element,
|
||||||
|
finishers: finishers,
|
||||||
|
extras: extras
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function _decorateConstructor(elements, decorators) {
|
||||||
|
var finishers = [];
|
||||||
|
for(var i = decorators.length - 1; i >= 0; i--){
|
||||||
|
var obj = _fromClassDescriptor(elements);
|
||||||
|
var elementsAndFinisher = _toClassDescriptor((0, decorators[i])(obj) || obj);
|
||||||
|
if (elementsAndFinisher.finisher !== undefined) {
|
||||||
|
finishers.push(elementsAndFinisher.finisher);
|
||||||
|
}
|
||||||
|
if (elementsAndFinisher.elements !== undefined) {
|
||||||
|
elements = elementsAndFinisher.elements;
|
||||||
|
for(var j = 0; j < elements.length - 1; j++){
|
||||||
|
for(var k = j + 1; k < elements.length; k++){
|
||||||
|
if (elements[j].key === elements[k].key && elements[j].placement === elements[k].placement) {
|
||||||
|
throw new TypeError("Duplicated element (" + elements[j].key + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
elements: elements,
|
||||||
|
finishers: finishers
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function _fromElementDescriptor(element) {
|
||||||
|
var obj = {
|
||||||
|
kind: element.kind,
|
||||||
|
key: element.key,
|
||||||
|
placement: element.placement,
|
||||||
|
descriptor: element.descriptor
|
||||||
|
};
|
||||||
|
var desc = {
|
||||||
|
value: "Descriptor",
|
||||||
|
configurable: true
|
||||||
|
};
|
||||||
|
Object.defineProperty(obj, Symbol.toStringTag, desc);
|
||||||
|
if (element.kind === "field") obj.initializer = element.initializer;
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
function _toElementDescriptors(elementObjects) {
|
||||||
|
if (elementObjects === undefined) return;
|
||||||
|
return (0, _toArray).default(elementObjects).map(function(elementObject) {
|
||||||
|
var element = _toElementDescriptor(elementObject);
|
||||||
|
_disallowProperty(elementObject, "finisher", "An element descriptor");
|
||||||
|
_disallowProperty(elementObject, "extras", "An element descriptor");
|
||||||
|
return element;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function _toElementDescriptor(elementObject) {
|
||||||
|
var kind = String(elementObject.kind);
|
||||||
|
if (kind !== "method" && kind !== "field") {
|
||||||
|
throw new TypeError('An element descriptor\'s .kind property must be either "method" or' + ' "field", but a decorator created an element descriptor with' + ' .kind "' + kind + '"');
|
||||||
|
}
|
||||||
|
var key = (0, _toPropertyKey).default(elementObject.key);
|
||||||
|
var placement = String(elementObject.placement);
|
||||||
|
if (placement !== "static" && placement !== "prototype" && placement !== "own") {
|
||||||
|
throw new TypeError('An element descriptor\'s .placement property must be one of "static",' + ' "prototype" or "own", but a decorator created an element descriptor' + ' with .placement "' + placement + '"');
|
||||||
|
}
|
||||||
|
var descriptor = elementObject.descriptor;
|
||||||
|
_disallowProperty(elementObject, "elements", "An element descriptor");
|
||||||
|
var element = {
|
||||||
|
kind: kind,
|
||||||
|
key: key,
|
||||||
|
placement: placement,
|
||||||
|
descriptor: Object.assign({}, descriptor)
|
||||||
|
};
|
||||||
|
if (kind !== "field") {
|
||||||
|
_disallowProperty(elementObject, "initializer", "A method descriptor");
|
||||||
|
} else {
|
||||||
|
_disallowProperty(descriptor, "get", "The property descriptor of a field descriptor");
|
||||||
|
_disallowProperty(descriptor, "set", "The property descriptor of a field descriptor");
|
||||||
|
_disallowProperty(descriptor, "value", "The property descriptor of a field descriptor");
|
||||||
|
element.initializer = elementObject.initializer;
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
function _toElementFinisherExtras(elementObject) {
|
||||||
|
var element = _toElementDescriptor(elementObject);
|
||||||
|
var finisher = _optionalCallableProperty(elementObject, "finisher");
|
||||||
|
var extras = _toElementDescriptors(elementObject.extras);
|
||||||
|
return {
|
||||||
|
element: element,
|
||||||
|
finisher: finisher,
|
||||||
|
extras: extras
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function _fromClassDescriptor(elements) {
|
||||||
|
var obj = {
|
||||||
|
kind: "class",
|
||||||
|
elements: elements.map(_fromElementDescriptor)
|
||||||
|
};
|
||||||
|
var desc = {
|
||||||
|
value: "Descriptor",
|
||||||
|
configurable: true
|
||||||
|
};
|
||||||
|
Object.defineProperty(obj, Symbol.toStringTag, desc);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
function _toClassDescriptor(obj) {
|
||||||
|
var kind = String(obj.kind);
|
||||||
|
if (kind !== "class") {
|
||||||
|
throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator' + ' created a class descriptor with .kind "' + kind + '"');
|
||||||
|
}
|
||||||
|
_disallowProperty(obj, "key", "A class descriptor");
|
||||||
|
_disallowProperty(obj, "placement", "A class descriptor");
|
||||||
|
_disallowProperty(obj, "descriptor", "A class descriptor");
|
||||||
|
_disallowProperty(obj, "initializer", "A class descriptor");
|
||||||
|
_disallowProperty(obj, "extras", "A class descriptor");
|
||||||
|
var finisher = _optionalCallableProperty(obj, "finisher");
|
||||||
|
var elements = _toElementDescriptors(obj.elements);
|
||||||
|
return {
|
||||||
|
elements: elements,
|
||||||
|
finisher: finisher
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function _disallowProperty(obj, name, objectType) {
|
||||||
|
if (obj[name] !== undefined) {
|
||||||
|
throw new TypeError(objectType + " can't have a ." + name + " property.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function _optionalCallableProperty(obj, name) {
|
||||||
|
var value = obj[name];
|
||||||
|
if (value !== undefined && typeof value !== "function") {
|
||||||
|
throw new TypeError("Expected '" + name + "' to be a function");
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
function _runClassFinishers(constructor, finishers) {
|
||||||
|
for(var i = 0; i < finishers.length; i++){
|
||||||
|
var newConstructor = (0, finishers[i])(constructor);
|
||||||
|
if (newConstructor !== undefined) {
|
||||||
|
if (typeof newConstructor !== "function") {
|
||||||
|
throw new TypeError("Finishers must return a constructor.");
|
||||||
|
}
|
||||||
|
constructor = newConstructor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return constructor;
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _defaults;
|
||||||
|
function _defaults(obj, defaults) {
|
||||||
|
var keys = Object.getOwnPropertyNames(defaults);
|
||||||
|
for(var i = 0; i < keys.length; i++){
|
||||||
|
var key = keys[i];
|
||||||
|
var value = Object.getOwnPropertyDescriptor(defaults, key);
|
||||||
|
if (value && value.configurable && obj[key] === undefined) {
|
||||||
|
Object.defineProperty(obj, key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _defineEnumerableProperties;
|
||||||
|
function _defineEnumerableProperties(obj, descs) {
|
||||||
|
for(var key in descs){
|
||||||
|
var desc = descs[key];
|
||||||
|
desc.configurable = desc.enumerable = true;
|
||||||
|
if ("value" in desc) desc.writable = true;
|
||||||
|
Object.defineProperty(obj, key, desc);
|
||||||
|
}
|
||||||
|
if (Object.getOwnPropertySymbols) {
|
||||||
|
var objectSymbols = Object.getOwnPropertySymbols(descs);
|
||||||
|
for(var i = 0; i < objectSymbols.length; i++){
|
||||||
|
var sym = objectSymbols[i];
|
||||||
|
var desc = descs[sym];
|
||||||
|
desc.configurable = desc.enumerable = true;
|
||||||
|
if ("value" in desc) desc.writable = true;
|
||||||
|
Object.defineProperty(obj, sym, desc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _defineProperty;
|
||||||
|
function _defineProperty(obj, key, value) {
|
||||||
|
if (key in obj) {
|
||||||
|
Object.defineProperty(obj, key, {
|
||||||
|
value: value,
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true,
|
||||||
|
writable: true
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
obj[key] = value;
|
||||||
|
}
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
+22
@@ -0,0 +1,22 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _extends;
|
||||||
|
function _extends() {
|
||||||
|
return extends_.apply(this, arguments);
|
||||||
|
}
|
||||||
|
function extends_() {
|
||||||
|
extends_ = Object.assign || function(target) {
|
||||||
|
for(var i = 1; i < arguments.length; i++){
|
||||||
|
var source = arguments[i];
|
||||||
|
for(var key in source){
|
||||||
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
||||||
|
target[key] = source[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return target;
|
||||||
|
};
|
||||||
|
return extends_.apply(this, arguments);
|
||||||
|
}
|
||||||
+30
@@ -0,0 +1,30 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _get;
|
||||||
|
var _superPropBase = _interopRequireDefault(require("./_super_prop_base"));
|
||||||
|
function _get(target, property, receiver) {
|
||||||
|
return get(target, property, receiver);
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function get(target1, property1, receiver1) {
|
||||||
|
if (typeof Reflect !== "undefined" && Reflect.get) {
|
||||||
|
get = Reflect.get;
|
||||||
|
} else {
|
||||||
|
get = function get(target, property, receiver) {
|
||||||
|
var base = (0, _superPropBase).default(target, property);
|
||||||
|
if (!base) return;
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(base, property);
|
||||||
|
if (desc.get) {
|
||||||
|
return desc.get.call(receiver || target);
|
||||||
|
}
|
||||||
|
return desc.value;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return get(target1, property1, receiver1);
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _getPrototypeOf;
|
||||||
|
function _getPrototypeOf(o) {
|
||||||
|
return getPrototypeOf(o);
|
||||||
|
}
|
||||||
|
function getPrototypeOf(o1) {
|
||||||
|
getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
|
||||||
|
return o.__proto__ || Object.getPrototypeOf(o);
|
||||||
|
};
|
||||||
|
return getPrototypeOf(o1);
|
||||||
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _inherits;
|
||||||
|
var _setPrototypeOf = _interopRequireDefault(require("./_set_prototype_of"));
|
||||||
|
function _inherits(subClass, superClass) {
|
||||||
|
if (typeof superClass !== "function" && superClass !== null) {
|
||||||
|
throw new TypeError("Super expression must either be null or a function");
|
||||||
|
}
|
||||||
|
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
||||||
|
constructor: {
|
||||||
|
value: subClass,
|
||||||
|
writable: true,
|
||||||
|
configurable: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (superClass) (0, _setPrototypeOf).default(subClass, superClass);
|
||||||
|
}
|
||||||
|
function _interopRequireDefault(obj) {
|
||||||
|
return obj && obj.__esModule ? obj : {
|
||||||
|
default: obj
|
||||||
|
};
|
||||||
|
}
|
||||||
+10
@@ -0,0 +1,10 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _inheritsLoose;
|
||||||
|
function _inheritsLoose(subClass, superClass) {
|
||||||
|
subClass.prototype = Object.create(superClass.prototype);
|
||||||
|
subClass.prototype.constructor = subClass;
|
||||||
|
subClass.__proto__ = superClass;
|
||||||
|
}
|
||||||
+14
@@ -0,0 +1,14 @@
|
|||||||
|
"use strict";
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.default = _initializerDefineProperty;
|
||||||
|
function _initializerDefineProperty(target, property, descriptor, context) {
|
||||||
|
if (!descriptor) return;
|
||||||
|
Object.defineProperty(target, property, {
|
||||||
|
enumerable: descriptor.enumerable,
|
||||||
|
configurable: descriptor.configurable,
|
||||||
|
writable: descriptor.writable,
|
||||||
|
value: descriptor.initializer ? descriptor.initializer.call(context) : void 0
|
||||||
|
});
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user