meow
- Version 13.2.0
- Published
- 419 kB
- No dependencies
- MIT license
Install
npm i meow
yarn add meow
pnpm add meow
Overview
CLI app helper
Index
Functions
Type Aliases
Namespaces
Functions
function meow
meow: { <Flags extends AnyFlags>( helpMessage: string, options?: Options<Flags> ): Result<Flags>; <Flags extends AnyFlags>(options?: Options<Flags>): Result<Flags>;};
Parameter helpMessage
Shortcut for the
help
option.Example 1
#!/usr/bin/env nodeimport meow from 'meow';import foo from './index.js';const cli = meow(`Usage$ foo <input>Options--rainbow, -r Include a rainbowExamples$ foo unicorns --rainbow๐ unicorns ๐`, {importMeta: import.meta,flags: {rainbow: {type: 'boolean',shortFlag: 'r'}}});//{// input: ['unicorns'],// flags: {rainbow: true},// ...//}foo(cli.input.at(0), cli.flags);
Type Aliases
type Flag
type Flag<PrimitiveType extends FlagType, Type, IsMultiple = false> = { /** Type of value. (Possible values: `string` `boolean` `number`) */ readonly type?: PrimitiveType;
/** Limit valid values to a predefined set of choices.
@example ``` unicorn: { isMultiple: true, choices: ['rainbow', 'cat', 'unicorn'] } ``` */ readonly choices?: Type extends unknown[] ? Type : Type[];
/** Default value when the flag is not specified.
@example ``` unicorn: { type: 'boolean', default: true } ``` */ readonly default?: Type;
/** A short flag alias.
@example ``` unicorn: { shortFlag: 'u' } ``` */ readonly shortFlag?: string;
/** Other names for the flag.
@example ``` unicorn: { aliases: ['unicorns', 'uni'] } ``` */ readonly aliases?: string[];
/** Indicates a flag can be set multiple times. Values are turned into an array.
Multiple values are provided by specifying the flag multiple times, for example, `$ foo -u rainbow -u cat`. Space- or comma-separated values [currently *not* supported](https://github.com/sindresorhus/meow/issues/164).
@default false */ readonly isMultiple?: IsMultiple;
/** Determine if the flag is required.
If it's only known at runtime whether the flag is required or not you can pass a Function instead of a boolean, which based on the given flags and other non-flag arguments should decide if the flag is required.
- 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.
@default false
@example ``` isRequired: (flags, input) => { if (flags.otherFlag) { return true; }
return false; } ``` */ readonly isRequired?: boolean | IsRequiredPredicate;};
type FlagType
type FlagType = 'string' | 'boolean' | 'number';
type IsRequiredPredicate
type IsRequiredPredicate = ( flags: Readonly<AnyFlags>, input: readonly string[]) => boolean;
Callback function to determine if a flag is required during runtime.
Parameter flags
Contains the flags converted to camel-case excluding aliases.
Parameter input
Contains the non-flag arguments.
Returns
True if the flag is required, otherwise false.
type Options
type Options<Flags extends AnyFlags> = { /** Pass in [`import.meta`](https://nodejs.org/dist/latest/docs/api/esm.html#esm_import_meta). This is used to find the correct package.json file. */ readonly importMeta: ImportMeta;
/** 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 [currently *not* supported](https://github.com/sindresorhus/meow/issues/164). - `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 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: - 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.
Note that flags are always defined using a camel-case key (`myKey`), but will match arguments in kebab-case (`--my-key`).
@example ``` flags: { unicorn: { type: 'string', choices: ['rainbow', 'cat', 'unicorn'], default: ['rainbow', 'cat'], shortFlag: 'u', aliases: ['unicorns'] isMultiple: true, isRequired: (flags, input) => { if (flags.otherFlag) { return true; }
return false; } } } ``` */ readonly flags?: Flags;
/** Description to show above the help text. Default: The package.json `"description"` property.
Set it to `false` to disable it altogether. */ readonly description?: 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](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/template_strings) 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. */ readonly help?: string | false;
/** Set a custom version output. Default: The package.json `"version"` property.
Set it to `false` to disable it altogether. */ readonly version?: string | false;
/** 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`. */ readonly autoHelp?: boolean;
/** 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`. */ readonly autoVersion?: boolean;
/** `package.json` as an `Object`. Default: Closest `package.json` upwards.
Note: Setting this stops `meow` from finding a package.json.
_You most likely don't need this option._ */ readonly pkg?: Record<string, unknown>;
/** Custom arguments object.
@default process.argv.slice(2) */ readonly argv?: readonly string[];
/** Infer the argument type.
By default, the argument `5` in `$ foo 5` becomes a string. Enabling this would infer it as a number.
@default false */ readonly inferType?: boolean;
/** 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 ``` import meow from 'meow';
const cli = meow(` Usage $ foo
Options --rainbow, -r Include a rainbow --unicorn, -u Include a unicorn --no-sparkles Exclude sparkles
Examples $ foo ๐ unicornsโจ๐ `, { importMeta: import.meta, booleanDefault: undefined, flags: { rainbow: { type: 'boolean', default: true, shortFlag: 'r' }, unicorn: { type: 'boolean', default: false, shortFlag: 'u' }, cake: { type: 'boolean', shortFlag: 'c' }, sparkles: { type: 'boolean', default: true } } });
//{ // flags: { // rainbow: true, // unicorn: false, // sparkles: true // }, // unnormalizedFlags: { // rainbow: true, // r: true, // unicorn: false, // u: false, // sparkles: true // }, // โฆ //} ``` */ // eslint-disable-next-line @typescript-eslint/ban-types readonly booleanDefault?: boolean | null | undefined;
// TODO: Remove this in meow 14. /** Whether to use [hard-rejection](https://github.com/sindresorhus/hard-rejection) or not. Disabling this can be useful if you need to handle `process.on('unhandledRejection')` yourself.
@deprecated This is the default behavior since Node.js 16, so this option is moot. @default true */ readonly hardRejection?: boolean;
/** Whether to allow unknown flags or not.
@default true */ readonly allowUnknownFlags?: boolean;
/** The number of spaces to use for indenting the help text.
@default 2 */ readonly helpIndent?: number;};
type Result
type Result<Flags extends AnyFlags> = { /** Non-flag arguments. */ input: string[];
/** Flags converted to camelCase excluding aliases. */ flags: CamelCasedProperties<TypedFlags<Flags>> & Record<string, unknown>;
/** Flags converted camelCase including aliases. */ unnormalizedFlags: TypedFlags<Flags> & Record<string, unknown>;
/** The `package.json` object. */ pkg: PackageJson;
/** The help text used with `--help`. */ help: string;
/** Show the help text and exit with code.
@param exitCode - The exit code to use. Default: `2`. */ showHelp: (exitCode?: number) => never;
/** Show the version text and exit. */ showVersion: () => void;};
type TypedFlags
type TypedFlags<Flags extends AnyFlags> = { [F in keyof Flags]: Flags[F] extends { isMultiple: true } ? PossiblyOptionalFlag<Flags[F], Array<TypedFlag<Flags[F]>>> : PossiblyOptionalFlag<Flags[F], TypedFlag<Flags[F]>>;};
Namespaces
namespace global
namespace global {}
interface SymbolConstructor
interface SymbolConstructor {}
property observable
readonly observable: symbol;
namespace PackageJson
namespace PackageJson {}
interface NonStandardEntryPoints
interface NonStandardEntryPoints {}
property browser
browser?: string | Partial<Record<string, string | false>>;
A hint to JavaScript bundlers or component tools when packaging modules for client side use.
property esnext
esnext?: | string | { [moduleName: string]: string | undefined; main?: string; browser?: string; };
A module ID with untranspiled code that is the primary entry point to the program.
property module
module?: string;
An ECMAScript module ID that is the primary entry point to the program.
property sideEffects
sideEffects?: boolean | string[];
Denote which files in your project are "pure" and therefore safe for Webpack to prune if unused.
[Read more.](https://webpack.js.org/guides/tree-shaking/)
interface PackageJsonStandard
interface PackageJsonStandard {}
Type for [npm's
package.json
file](https://docs.npmjs.com/creating-a-package-json-file). Containing standard npm properties.
property author
author?: Person;
property bin
bin?: string | Partial<Record<string, string>>;
The executable files that should be installed into the
PATH
.
property bugs
bugs?: BugsLocation;
The URL to the package's issue tracker and/or the email address to which issues should be reported.
property bundledDependencies
bundledDependencies?: string[];
Package names that are bundled when the package is published.
property bundleDependencies
bundleDependencies?: string[];
Alias of
bundledDependencies
.
property config
config?: JsonObject;
Is used to set configuration parameters used in package scripts that persist across upgrades.
property contributors
contributors?: Person[];
A list of people who contributed to the package.
property cpu
cpu?: Array< LiteralUnion< | 'arm' | 'arm64' | 'ia32' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 's390' | 's390x' | 'x32' | 'x64' | '!arm' | '!arm64' | '!ia32' | '!mips' | '!mipsel' | '!ppc' | '!ppc64' | '!s390' | '!s390x' | '!x32' | '!x64', string >>;
CPU architectures the module runs on.
property dependencies
dependencies?: Dependency;
The dependencies of the package.
property description
description?: string;
Package description, listed in
npm search
.
property devDependencies
devDependencies?: Dependency;
Additional tooling dependencies that are not required for the package to work. Usually test, build, or documentation tooling.
property directories
directories?: DirectoryLocations;
Indicates the structure of the package.
property engines
engines?: { [EngineName in 'npm' | 'node' | string]?: string;};
Engines that this package runs on.
property engineStrict
engineStrict?: boolean;
Deprecated
property exports
exports?: Exports;
Subpath exports to define entry points of the package.
[Read more.](https://nodejs.org/api/packages.html#subpath-exports)
property files
files?: string[];
The files included in the package.
property funding
funding?: | string | { /** The type of funding. */ type?: LiteralUnion< | 'github' | 'opencollective' | 'patreon' | 'individual' | 'foundation' | 'corporation', string >;
/** The URL to the funding page. */ url: string; };
Describes and notifies consumers of a package's monetary support information.
[Read more.](https://github.com/npm/rfcs/blob/latest/accepted/0017-add-funding-support.md)
property homepage
homepage?: LiteralUnion<'.', string>;
The URL to the package's homepage.
property imports
imports?: Imports;
Subpath imports to define internal package import maps that only apply to import specifiers from within the package itself.
[Read more.](https://nodejs.org/api/packages.html#subpath-imports)
property keywords
keywords?: string[];
Keywords associated with package, listed in
npm search
.
property license
license?: string;
The license for the package.
property licenses
licenses?: Array<{ type?: string; url?: string;}>;
The licenses for the package.
property main
main?: string;
The module ID that is the primary entry point to the program.
property maintainers
maintainers?: Person[];
A list of people who maintain the package.
property man
man?: string | string[];
Filenames to put in place for the
man
program to find.
property name
name?: string;
The name of the package.
property optionalDependencies
optionalDependencies?: Dependency;
Dependencies that are skipped if they fail to install.
property os
os?: Array< LiteralUnion< | 'aix' | 'darwin' | 'freebsd' | 'linux' | 'openbsd' | 'sunos' | 'win32' | '!aix' | '!darwin' | '!freebsd' | '!linux' | '!openbsd' | '!sunos' | '!win32', string >>;
Operating systems the module runs on.
property peerDependencies
peerDependencies?: Dependency;
Dependencies that will usually be required by the package user directly or via another dependency.
property peerDependenciesMeta
peerDependenciesMeta?: Partial<Record<string, { optional: true }>>;
Indicate peer dependencies that are optional.
property preferGlobal
preferGlobal?: boolean;
If set to
true
, a warning will be shown if package is installed locally. Useful if the package is primarily a command-line application that should be installed globally.Deprecated
property private
private?: boolean;
If set to
true
, then npm will refuse to publish it.
property publishConfig
publishConfig?: PublishConfig;
A set of config values that will be used at publish-time. It's especially handy to set the tag, registry or access, to ensure that a given package is not tagged with 'latest', published to the global public registry or that a scoped module is private by default.
property repository
repository?: | string | { type: string; url: string;
/** Relative path to package.json if it is placed in non-root directory (for example if it is part of a monorepo).
[Read more.](https://github.com/npm/rfcs/blob/latest/implemented/0010-monorepo-subdirectory-declaration.md) */ directory?: string; };
Location for the code repository.
property scripts
scripts?: Scripts;
Script commands that are run at various times in the lifecycle of the package. The key is the lifecycle event, and the value is the command to run at that point.
property type
type?: 'module' | 'commonjs';
Resolution algorithm for importing ".js" files from the package's scope.
[Read more.](https://nodejs.org/api/esm.html#esm_package_json_type_field)
property version
version?: string;
Package version, parseable by [
node-semver
](https://github.com/npm/node-semver).
property workspaces
workspaces?: WorkspacePattern[] | WorkspaceConfig;
Used to configure [npm workspaces](https://docs.npmjs.com/cli/using-npm/workspaces) / [Yarn workspaces](https://classic.yarnpkg.com/docs/workspaces/).
Workspaces allow you to manage multiple packages within the same repository in such a way that you only need to run your install command once in order to install all of them in a single pass.
Please note that the top-level
private
property ofpackage.json
**must** be set totrue
in order to use workspaces.
type BugsLocation
type BugsLocation = | string | { /** The URL to the package's issue tracker. */ url?: string;
/** The email address to which issues should be reported. */ email?: string; };
type Dependency
type Dependency = Partial<Record<string, string>>;
Dependencies of the package. The version range is a string which has one or more space-separated descriptors. Dependencies can also be identified with a tarball or Git URL.
type DirectoryLocations
type DirectoryLocations = { [directoryType: string]: JsonValue | undefined;
/** Location for executable scripts. Sugar to generate entries in the `bin` property by walking the folder. */ bin?: string;
/** Location for Markdown files. */ doc?: string;
/** Location for example scripts. */ example?: string;
/** Location for the bulk of the library. */ lib?: string;
/** Location for man pages. Sugar to generate a `man` array by walking the folder. */ man?: string;
/** Location for test files. */ test?: string;};
type ExportConditions
type ExportConditions = { // eslint-disable-line @typescript-eslint/consistent-indexed-object-style [condition: string]: Exports;};
A mapping of conditions and the paths to which they resolve.
type Exports
type Exports = null | string | Array<string | ExportConditions> | ExportConditions;
Entry points of a module, optionally with conditions and subpath exports.
type Imports
type Imports = { // eslint-disable-line @typescript-eslint/consistent-indexed-object-style [key: `#${string}`]: Exports;};
Import map entries of a module, optionally with conditions and subpath imports.
type JSPMConfiguration
type JSPMConfiguration = { /** JSPM configuration. */ jspm?: PackageJson;};
type NodeJsStandard
type NodeJsStandard = { /** Defines which package manager is expected to be used when working on the current project. It can set to any of the [supported package managers](https://nodejs.org/api/corepack.html#supported-package-managers), and will ensure that your teams use the exact same package manager versions without having to install anything else than Node.js.
__This field is currently experimental and needs to be opted-in; check the [Corepack](https://nodejs.org/api/corepack.html) page for details about the procedure.__
@example ```json { "packageManager": "<package manager name>@<version>" } ``` */ packageManager?: string;};
Type for [
package.json
file used by the Node.js runtime](https://nodejs.org/api/packages.html#nodejs-packagejson-field-definitions).
type Person
type Person = | string | { name: string; url?: string; email?: string; };
A person who has been involved in creating or maintaining the package.
type PublishConfig
type PublishConfig = { /** Additional, less common properties from the [npm docs on `publishConfig`](https://docs.npmjs.com/cli/v7/configuring-npm/package-json#publishconfig). */ [additionalProperties: string]: JsonValue | undefined;
/** When publishing scoped packages, the access level defaults to restricted. If you want your scoped package to be publicly viewable (and installable) set `--access=public`. The only valid values for access are public and restricted. Unscoped packages always have an access level of public. */ access?: 'public' | 'restricted';
/** The base URL of the npm registry.
Default: `'https://registry.npmjs.org/'` */ registry?: string;
/** The tag to publish the package under.
Default: `'latest'` */ tag?: string;};
type Scripts
type Scripts = { /** Run **before** the package is published (Also run on local `npm install` without any arguments). */ prepublish?: string;
/** Run both **before** the package is packed and published, and on local `npm install` without any arguments. This is run **after** `prepublish`, but **before** `prepublishOnly`. */ prepare?: string;
/** Run **before** the package is prepared and packed, **only** on `npm publish`. */ prepublishOnly?: string;
/** Run **before** a tarball is packed (on `npm pack`, `npm publish`, and when installing git dependencies). */ prepack?: string;
/** Run **after** the tarball has been generated and moved to its final destination. */ postpack?: string;
/** Run **after** the package is published. */ publish?: string;
/** Run **after** the package is published. */ postpublish?: string;
/** Run **before** the package is installed. */ preinstall?: string;
/** Run **after** the package is installed. */ install?: string;
/** Run **after** the package is installed and after `install`. */ postinstall?: string;
/** Run **before** the package is uninstalled and before `uninstall`. */ preuninstall?: string;
/** Run **before** the package is uninstalled. */ uninstall?: string;
/** Run **after** the package is uninstalled. */ postuninstall?: string;
/** Run **before** bump the package version and before `version`. */ preversion?: string;
/** Run **before** bump the package version. */ version?: string;
/** Run **after** bump the package version. */ postversion?: string;
/** Run with the `npm test` command, before `test`. */ pretest?: string;
/** Run with the `npm test` command. */ test?: string;
/** Run with the `npm test` command, after `test`. */ posttest?: string;
/** Run with the `npm stop` command, before `stop`. */ prestop?: string;
/** Run with the `npm stop` command. */ stop?: string;
/** Run with the `npm stop` command, after `stop`. */ poststop?: string;
/** Run with the `npm start` command, before `start`. */ prestart?: string;
/** Run with the `npm start` command. */ start?: string;
/** Run with the `npm start` command, after `start`. */ poststart?: string;
/** Run with the `npm restart` command, before `restart`. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided. */ prerestart?: string;
/** Run with the `npm restart` command. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided. */ restart?: string;
/** Run with the `npm restart` command, after `restart`. Note: `npm restart` will run the `stop` and `start` scripts if no `restart` script is provided. */ postrestart?: string;} & Partial<Record<string, string>>;
type TypeScriptConfiguration
type TypeScriptConfiguration = { /** Location of the bundled TypeScript declaration file. */ types?: string;
/** Version selection map of TypeScript. */ typesVersions?: Partial<Record<string, Partial<Record<string, string[]>>>>;
/** Location of the bundled TypeScript declaration file. Alias of `types`. */ typings?: string;};
type WorkspaceConfig
type WorkspaceConfig = { /** An array of workspace pattern strings which contain the workspace packages. */ packages?: WorkspacePattern[];
/** Designed to solve the problem of packages which break when their `node_modules` are moved to the root workspace directory - a process known as hoisting. For these packages, both within your workspace, and also some that have been installed via `node_modules`, it is important to have a mechanism for preventing the default Yarn workspace behavior. By adding workspace pattern strings here, Yarn will resume non-workspace behavior for any package which matches the defined patterns.
[Supported](https://classic.yarnpkg.com/blog/2018/02/15/nohoist/) by Yarn. [Not supported](https://github.com/npm/rfcs/issues/287) by npm. */ nohoist?: WorkspacePattern[];};
An alternative configuration for workspaces.
type WorkspacePattern
type WorkspacePattern = string;
A workspace pattern points to a directory or group of directories which contain packages that should be included in the workspace installation process.
The patterns are handled with [minimatch](https://github.com/isaacs/minimatch).
Example 1
docs
โ Include the docs directory and install its dependencies.packages/*
โ Include all nested directories within the packages directory, likepackages/cli
andpackages/core
.
type YarnConfiguration
type YarnConfiguration = { /** If your package only allows one version of a given dependency, and youโd like to enforce the same behavior as `yarn install --flat` on the command-line, set this to `true`.
Note that if your `package.json` contains `"flat": true` and other packages depend on yours (e.g. you are building a library rather than an app), those other packages will also need `"flat": true` in their `package.json` or be installed with `yarn install --flat` on the command-line. */ flat?: boolean;
/** Selective version resolutions. Allows the definition of custom package versions inside dependencies without manual edits in the `yarn.lock` file. */ resolutions?: Dependency;};
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (27)
- @rollup/plugin-commonjs
- @rollup/plugin-json
- @rollup/plugin-node-resolve
- @types/minimist
- ava
- camelcase-keys
- common-tags
- decamelize
- decamelize-keys
- delete_comments
- execa
- globby
- indent-string
- minimist-options
- normalize-package-data
- read-package-up
- read-pkg
- redent
- rollup
- rollup-plugin-dts
- rollup-plugin-license
- trim-newlines
- tsd
- type-fest
- typescript
- xo
- yargs-parser
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/meow
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/meow)
- HTML<a href="https://www.jsdocs.io/package/meow"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4103 ms. - Missing or incorrect documentation? Open an issue for this package.