Gathering detailed insights and metrics for @0xengine/meow
Gathering detailed insights and metrics for @0xengine/meow
Gathering detailed insights and metrics for @0xengine/meow
Gathering detailed insights and metrics for @0xengine/meow
npm install @0xengine/meow
Typescript
Module System
Min. Node Version
Node Version
NPM Version
75.4
Supply Chain
99.6
Quality
81
Maintenance
100
Vulnerability
99.6
License
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
28
CLI app helper
--no-
prefix--version
--help
1npm install @xengine/meow
1./foo-app.js unicorns --rainbow
1#!/usr/bin/env node 2import meow from 'meow'; 3import foo from './lib/index.js'; 4 5const cli = meow(` 6 Usage 7 $ foo <input> 8 9 Options 10 --rainbow, -r Include a rainbow 11 12 Examples 13 $ foo unicorns --rainbow 14 🌈 unicorns 🌈 15`, { 16 importMeta: import.meta, // This is required 17 flags: { 18 rainbow: { 19 type: 'boolean', 20 shortFlag: 'r' 21 } 22 } 23}); 24/* 25{ 26 input: ['unicorns'], 27 flags: {rainbow: true}, 28 ... 29} 30*/ 31 32foo(cli.input.at(0), cli.flags);
Returns an object
with:
input
(Array) - Non-flag argumentsflags
(Object) - Flags converted to camelCase excluding aliasesunnormalizedFlags
(Object) - Flags converted to camelCase including aliasespkg
(Object) - The package.json
objecthelp
(string) - The help text used with --help
showHelp([exitCode=2])
(Function) - Show the help text and exit with exitCode
showVersion()
(Function) - Show the version text and exitType: string
Shortcut for the help
option.
Type: object
Required
Type: object
Pass in import.meta
. This is used to find the correct package.json file.
Type: object
Define argument flags.
The key is the flag name in camel-case and the value is an object with any of:
type
: Type of value. (Possible values: string
boolean
number
)choices
: Limit valid values to a predefined set of choices.default
: Default value when the flag is not specified.shortFlag
: A short flag alias.aliases
: Other names for the flag.isRequired
: Determine if the flag is required. (Default: false)
Function
instead of a boolean
, which based on the given flags and other non-flag arguments, should decide if the flag is required. Two arguments are passed to the function:boolean
, true if the flag is required, otherwise false.Note that flags are always defined using a camel-case key (myKey
), but will match arguments in kebab-case (--my-key
).
Example:
1flags: { 2 unicorn: { 3 type: 'string', 4 choices: ['rainbow', 'cat', 'unicorn'], 5 default: ['rainbow', 'cat'], 6 shortFlag: 'u', 7 aliases: ['unicorns'], 8 isMultiple: true, 9 isRequired: (flags, input) => { 10 if (flags.otherFlag) { 11 return true; 12 } 13 14 return false; 15 } 16 } 17}
Type: string | false
Default: The package.json "description"
property
Description to show above the help text.
Set it to false
to disable it altogether.
Type: string | false
The help text you want shown.
The input is reindented and starting/ending newlines are trimmed which means you can use a template literal without having to care about using the correct amount of indent.
The description will be shown above your help text automatically.
Set it to false
to disable it altogether.
Type: string
Default: The package.json "version"
property
Set a custom version output.
Type: boolean
Default: true
Automatically show the help text when the --help
flag is present. Useful to set this value to false
when a CLI manages child CLIs with their own help text.
This option is only considered when there is only one argument in process.argv
.
Type: boolean
Default: true
Automatically show the version text when the --version
flag is present. Useful to set this value to false
when a CLI manages child CLIs with their own version text.
This option is only considered when there is only one argument in process.argv
.
Type: object
Default: Closest package.json upwards
package.json as an object
.
Note: Setting this stops meow
from finding a package.json.
You most likely don't need this option.
Type: string[]
Default: process.argv.slice(2)
Custom arguments object.
Type: boolean
Default: false
Infer the argument type.
By default, the argument 5
in $ foo 5
becomes a string. Enabling this would infer it as a number.
Type: boolean | undefined
Default: false
Value of boolean
flags not defined in argv
.
If set to undefined
, the flags not defined in argv
will be excluded from the result.
The default
value set in boolean
flags take precedence over booleanDefault
.
Note: If used in conjunction with isMultiple
, the default flag value is set to []
.
Caution: Explicitly specifying undefined
for booleanDefault
has different meaning from omitting key itself.
Example:
1import meow from 'meow'; 2 3const cli = meow(` 4 Usage 5 $ foo 6 7 Options 8 --rainbow, -r Include a rainbow 9 --unicorn, -u Include a unicorn 10 --no-sparkles Exclude sparkles 11 12 Examples 13 $ foo 14 🌈 unicorns✨🌈 15`, { 16 importMeta: import.meta, 17 booleanDefault: undefined, 18 flags: { 19 rainbow: { 20 type: 'boolean', 21 default: true, 22 shortFlag: 'r' 23 }, 24 unicorn: { 25 type: 'boolean', 26 default: false, 27 shortFlag: 'u' 28 }, 29 cake: { 30 type: 'boolean', 31 shortFlag: 'c' 32 }, 33 sparkles: { 34 type: 'boolean', 35 default: true 36 } 37 } 38}); 39/* 40{ 41 flags: { 42 rainbow: true, 43 unicorn: false, 44 sparkles: true 45 }, 46 unnormalizedFlags: { 47 rainbow: true, 48 r: true, 49 unicorn: false, 50 u: false, 51 sparkles: true 52 }, 53 … 54} 55*/
Type boolean
Default: true
Whether to allow unknown flags or not.
Type number
Default: 2
The number of spaces to use for indenting the help text.
See chalk
if you want to colorize the terminal output.
See get-stdin
if you want to accept input from stdin.
See conf
if you need to persist some data.
No vulnerabilities found.