Installations
npm install meow
Developer Guide
Typescript
No
Module System
ESM
Min. Node Version
>=18
Node Version
20.11.0
NPM Version
9.2.0
Score
95.7
Supply Chain
99.6
Quality
77.8
Maintenance
100
Vulnerability
99.6
License
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (88.73%)
TypeScript (11.27%)
Developer
sindresorhus
Download Statistics
Total Downloads
4,995,478,984
Last Day
1,020,366
Last Week
13,703,125
Last Month
86,613,599
Last Year
1,012,603,476
GitHub Statistics
3,558 Stars
198 Commits
151 Forks
23 Watching
1 Branches
44 Contributors
Sponsor this package
Package Meta Information
Latest Version
13.2.0
Package Id
meow@13.2.0
Unpacked Size
409.28 kB
Size
88.90 kB
File Count
11
NPM Version
9.2.0
Node Version
20.11.0
Publised On
06 Feb 2024
Total Downloads
Cumulative downloads
Total Downloads
4,995,478,984
Last day
-73.4%
1,020,366
Compared to previous day
Last week
-33.1%
13,703,125
Compared to previous week
Last month
-13.1%
86,613,599
Compared to previous month
Last year
9.3%
1,012,603,476
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dev Dependencies
27
meow
CLI app helper
I would recommend reading this guide on how to make user-friendly command-line tools.
Features
- Parses arguments
- Converts flags to camelCase
- Negates flags when using the
--no-
prefix - Outputs version when
--version
- Outputs description and supplied help text when
--help
- Makes unhandled rejected promises fail hard instead of the default silent fail
- Sets the process title to the binary name defined in package.json
- No dependencies!
Install
1npm install meow
Usage
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, 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);
API
meow(helpText, options?)
meow(options)
Returns an object
with:
input
(Array) - Non-flag argumentsflags
(Object) - Flags converted to camelCase excluding aliasesunnormalizedFlags
(Object) - Flags converted to camelCase including aliasespkg
(Object) - Thepackage.json
objecthelp
(string) - The help text used with--help
showHelp([exitCode=2])
(Function) - Show the help text and exit withexitCode
showVersion()
(Function) - Show the version text and exit
helpText
Type: string
Shortcut for the help
option.
options
Type: object
importMeta
Type: object
Pass in import.meta
. This is used to find the correct package.json file.
flags
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.isMultiple
: Indicates a flag can be set multiple times. Values are turned into an array. (Default: false)- Multiple values are provided by specifying the flag multiple times, for example,
$ foo -u rainbow -u cat
. Space- or comma-separated values are currently not supported.
- Multiple values are provided by specifying the flag multiple times, for example,
isRequired
: Determine if the flag is required. (Default: false)- If it's only known at runtime whether the flag is required or not, you can pass a
Function
instead of aboolean
, 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: - The first argument is the flags object, which contains the flags converted to camel-case excluding aliases.
- The second argument is the input string array, which contains the non-flag arguments.
- The function should return a
boolean
, true if the flag is required, otherwise false.
- If it's only known at runtime whether the flag is required or not, you can pass a
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}
description
Type: string | boolean
Default: The package.json "description"
property
Description to show above the help text.
Set it to false
to disable it altogether.
help
Type: string | boolean
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.
version
Type: string | boolean
Default: The package.json "version"
property
Set a custom version output.
autoHelp
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
.
autoVersion
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
.
pkg
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.
argv
Type: string[]
Default: process.argv.slice(2)
Custom arguments object.
inferType
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.
booleanDefault
Type: boolean | null | 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*/
allowUnknownFlags
Type boolean
Default: true
Whether to allow unknown flags or not.
helpIndent
Type number
Default: 2
The number of spaces to use for indenting the help text.
Promises
Meow will make unhandled rejected promises fail hard instead of the default silent fail. Meaning you don't have to manually .catch()
promises used in your CLI.
Tips
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.
Reason
no dangerous workflow patterns detected
Reason
security policy file detected
Details
- Info: security policy file detected: .github/security.md:1
- Info: Found linked content: .github/security.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: .github/security.md:1
- Info: Found text in security policy: .github/security.md:1
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: license:0
- Info: FSF or OSI recognized license: MIT License: license:0
Reason
0 existing vulnerabilities detected
Reason
Found 17/30 approved changesets -- score normalized to 5
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/meow/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/sindresorhus/meow/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:22
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 17 are checked with a SAST tool
Score
4.5
/10
Last Scanned on 2024-12-16
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to meow
@types/meow
Stub TypeScript definitions entry for meow, which provides its own types definitions
cli-meow-help
Generate automatically formatted help text for `meow` CLI helper
meow-angular
Meow应用框架Meow.Ui.Angular库配套的ts代码库
@fontsource/meow-script
Self-host the Meow Script font in a neatly bundled NPM package.