Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

meow

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

meow - npm Package Compare versions

Comparing version 9.0.0 to 10.0.0

416

index.d.ts
import {PackageJson} from 'type-fest';
declare namespace meow {
type FlagType = 'string' | 'boolean' | 'number';
export type FlagType = 'string' | 'boolean' | 'number';
/**
Callback function to determine if a flag is required during runtime.
/**
Callback function to determine if a flag is required during runtime.
@param flags - Contains the flags converted to camel-case excluding aliases.
@param input - Contains the non-flag arguments.
@param flags - Contains the flags converted to camel-case excluding aliases.
@param input - Contains the non-flag arguments.
@returns True if the flag is required, otherwise false.
*/
type IsRequiredPredicate = (flags: Readonly<AnyFlags>, input: readonly string[]) => boolean;
@returns True if the flag is required, otherwise false.
*/
export type IsRequiredPredicate = (flags: Readonly<AnyFlags>, input: readonly string[]) => boolean;
interface Flag<Type extends FlagType, Default> {
readonly type?: Type;
readonly alias?: string;
readonly default?: Default;
readonly isRequired?: boolean | IsRequiredPredicate;
readonly isMultiple?: boolean;
}
export interface Flag<Type extends FlagType, Default> {
readonly type?: Type;
readonly alias?: string;
readonly default?: Default;
readonly isRequired?: boolean | IsRequiredPredicate;
readonly isMultiple?: boolean;
}
type StringFlag = Flag<'string', string>;
type BooleanFlag = Flag<'boolean', boolean>;
type NumberFlag = Flag<'number', number>;
type StringFlag = Flag<'string', string>;
type BooleanFlag = Flag<'boolean', boolean>;
type NumberFlag = Flag<'number', number>;
type AnyFlag = StringFlag | BooleanFlag | NumberFlag;
type AnyFlags = Record<string, AnyFlag>;
type AnyFlag = StringFlag | BooleanFlag | NumberFlag;
type AnyFlags = Record<string, AnyFlag>;
export interface 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;
interface Options<Flags extends AnyFlags> {
/**
Define argument flags.
/**
Define argument flags.
The key is the flag name in camel-case and the value is an object with any of:
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`)
- `alias`: Usually used to define a short flag alias.
- `default`: Default value when the flag is not specified.
- `isRequired`: 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.
- `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 *not* supported.
- `type`: Type of value. (Possible values: `string` `boolean` `number`)
- `alias`: Usually used to define a short flag alias.
- `default`: Default value when the flag is not specified.
- `isRequired`: 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.
- `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 *not* supported.
Note that flags are always defined using a camel-case key (`myKey`), but will match arguments in kebab-case (`--my-key`).
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',
alias: 'u',
default: ['rainbow', 'cat'],
isMultiple: true,
isRequired: (flags, input) => {
if (flags.otherFlag) {
return true;
}
@example
```
flags: {
unicorn: {
type: 'string',
alias: 'u',
default: ['rainbow', 'cat'],
isMultiple: true,
isRequired: (flags, input) => {
if (flags.otherFlag) {
return true;
}
return false;
}
return false;
}
}
```
*/
readonly flags?: Flags;
}
```
*/
readonly flags?: Flags;
/**
Description to show above the help text. Default: The package.json `"description"` property.
/**
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;
Set it to `false` to disable it altogether.
*/
readonly description?: string | false;
/**
The help text you want shown.
/**
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 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.
The description will be shown above your help text automatically.
Set it to `false` to disable it altogether.
*/
readonly help?: string | false;
Set it to `false` to disable it altogether.
*/
readonly help?: string | false;
/**
Set a custom version output. Default: The package.json `"version"` property.
/**
Set a custom version output. Default: The package.json `"version"` property.
Set it to `false` to disable it altogether.
*/
readonly version?: string | false;
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.
/**
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;
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.
/**
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;
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.
/**
`package.json` as an `Object`. Default: Closest `package.json` upwards.
_You most likely don't need this option._
*/
readonly pkg?: Record<string, unknown>;
_You most likely don't need this option._
*/
readonly pkg?: Record<string, unknown>;
/**
Custom arguments object.
/**
Custom arguments object.
@default process.argv.slice(2)
*/
readonly argv?: readonly string[];
@default process.argv.slice(2)
*/
readonly argv?: readonly string[];
/**
Infer the argument type.
/**
Infer the argument type.
By default, the argument `5` in `$ foo 5` becomes a string. Enabling this would infer it as a number.
By default, the argument `5` in `$ foo 5` becomes a string. Enabling this would infer it as a number.
@default false
*/
readonly inferType?: boolean;
@default false
*/
readonly inferType?: boolean;
/**
Value of `boolean` flags not defined in `argv`.
/**
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`.
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 `[]`._
_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.__
__Caution: Explicitly specifying `undefined` for `booleanDefault` has different meaning from omitting key itself.__
@example
```
import meow = require('meow');
@example
```
import meow from 'meow';
const cli = meow(`
Usage
$ foo
const cli = meow(`
Usage
$ foo
Options
--rainbow, -r Include a rainbow
--unicorn, -u Include a unicorn
--no-sparkles Exclude sparkles
Options
--rainbow, -r Include a rainbow
--unicorn, -u Include a unicorn
--no-sparkles Exclude sparkles
Examples
$ foo
🌈 unicorns✨🌈
`, {
booleanDefault: undefined,
flags: {
rainbow: {
type: 'boolean',
default: true,
alias: 'r'
},
unicorn: {
type: 'boolean',
default: false,
alias: 'u'
},
cake: {
type: 'boolean',
alias: 'c'
},
sparkles: {
type: 'boolean',
default: true
}
Examples
$ foo
🌈 unicorns✨🌈
`, {
importMeta: import.meta,
booleanDefault: undefined,
flags: {
rainbow: {
type: 'boolean',
default: true,
alias: 'r'
},
unicorn: {
type: 'boolean',
default: false,
alias: 'u'
},
cake: {
type: 'boolean',
alias: 'c'
},
sparkles: {
type: 'boolean',
default: true
}
});
}
});
//{
// flags: {
// rainbow: true,
// unicorn: false,
// sparkles: true
// },
// unnormalizedFlags: {
// rainbow: true,
// r: true,
// unicorn: false,
// u: false,
// sparkles: true
// },
// …
//}
```
*/
readonly booleanDefault?: boolean | null | undefined;
//{
// flags: {
// rainbow: true,
// unicorn: false,
// sparkles: true
// },
// unnormalizedFlags: {
// rainbow: true,
// r: true,
// unicorn: false,
// u: false,
// sparkles: true
// },
// …
//}
```
*/
readonly booleanDefault?: boolean | null | undefined;
/**
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.
/**
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.
@default true
*/
readonly hardRejection?: boolean;
@default true
*/
readonly hardRejection?: boolean;
/**
Whether to allow unknown flags or not.
/**
Whether to allow unknown flags or not.
@default true
*/
readonly allowUnknownFlags?: boolean;
}
@default true
*/
readonly allowUnknownFlags?: boolean;
}
type TypedFlag<Flag extends AnyFlag> =
type TypedFlag<Flag extends AnyFlag> =
Flag extends {type: 'number'}

@@ -222,3 +226,3 @@ ? number

type PossiblyOptionalFlag<Flag extends AnyFlag, FlagType> =
type PossiblyOptionalFlag<Flag extends AnyFlag, FlagType> =
Flag extends {isRequired: true}

@@ -230,46 +234,45 @@ ? FlagType

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]>>
};
export 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]>>
};
interface Result<Flags extends AnyFlags> {
/**
Non-flag arguments.
*/
input: string[];
export interface Result<Flags extends AnyFlags> {
/**
Non-flag arguments.
*/
input: string[];
/**
Flags converted to camelCase excluding aliases.
*/
flags: TypedFlags<Flags> & Record<string, unknown>;
/**
Flags converted to camelCase excluding aliases.
*/
flags: TypedFlags<Flags> & Record<string, unknown>;
/**
Flags converted camelCase including aliases.
*/
unnormalizedFlags: TypedFlags<Flags> & Record<string, unknown>;
/**
Flags converted camelCase including aliases.
*/
unnormalizedFlags: TypedFlags<Flags> & Record<string, unknown>;
/**
The `package.json` object.
*/
pkg: PackageJson;
/**
The `package.json` object.
*/
pkg: PackageJson;
/**
The help text used with `--help`.
*/
help: string;
/**
The help text used with `--help`.
*/
help: string;
/**
Show the help text and exit with code.
/**
Show the help text and exit with code.
@param exitCode - The exit code to use. Default: `2`.
*/
showHelp: (exitCode?: number) => void;
@param exitCode - The exit code to use. Default: `2`.
*/
showHelp: (exitCode?: number) => void;
/**
Show the version text and exit.
*/
showVersion: () => void;
}
/**
Show the version text and exit.
*/
showVersion: () => void;
}

@@ -282,5 +285,4 @@ /**

#!/usr/bin/env node
'use strict';
import meow = require('meow');
import foo = require('.');
import meow from 'meow';
import foo from './index.js';

@@ -298,2 +300,3 @@ const cli = meow(`

`, {
importMeta: import.meta,
flags: {

@@ -316,5 +319,4 @@ rainbow: {

*/
declare function meow<Flags extends meow.AnyFlags>(helpMessage: string, options?: meow.Options<Flags>): meow.Result<Flags>;
declare function meow<Flags extends meow.AnyFlags>(options?: meow.Options<Flags>): meow.Result<Flags>;
export = meow;
export default function meow<Flags extends AnyFlags>(helpMessage: string, options?: Options<Flags>): Result<Flags>;
// eslint-disable-next-line no-redeclare
export default function meow<Flags extends AnyFlags>(options?: Options<Flags>): Result<Flags>;

@@ -1,18 +0,14 @@

'use strict';
const path = require('path');
const buildParserOptions = require('minimist-options');
const parseArguments = require('yargs-parser');
const camelCaseKeys = require('camelcase-keys');
const decamelize = require('decamelize');
const decamelizeKeys = require('decamelize-keys');
const trimNewlines = require('trim-newlines');
const redent = require('redent');
const readPkgUp = require('read-pkg-up');
const hardRejection = require('hard-rejection');
const normalizePackageData = require('normalize-package-data');
import {dirname} from 'node:path';
import {fileURLToPath} from 'node:url';
import buildParserOptions from 'minimist-options';
import parseArguments from 'yargs-parser';
import camelCaseKeys from 'camelcase-keys';
import decamelize from 'decamelize';
import decamelizeKeys from 'decamelize-keys';
import trimNewlines from 'trim-newlines';
import redent from 'redent';
import {readPackageUpSync} from 'read-pkg-up';
import hardRejection from 'hard-rejection';
import normalizePackageData from 'normalize-package-data';
// Prevent caching of this module so module.parent is always accurate
delete require.cache[__filename];
const parentDir = path.dirname(module.parent && module.parent.filename ? module.parent.filename : '.');
const isFlagMissing = (flagName, definedFlags, receivedFlags, input) => {

@@ -54,3 +50,3 @@ const flag = definedFlags[flagName];

for (const flag of missingRequiredFlags) {
console.error(`\t--${decamelize(flag.key, '-')}${flag.alias ? `, -${flag.alias}` : ''}`);
console.error(`\t--${decamelize(flag.key, {separator: '-'})}${flag.alias ? `, -${flag.alias}` : ''}`);
}

@@ -107,3 +103,3 @@ };

const meow = (helpText, options) => {
const meow = (helpText, options = {}) => {
if (typeof helpText !== 'string') {

@@ -114,4 +110,8 @@ options = helpText;

const foundPkg = readPkgUp.sync({
cwd: parentDir,
if (!(options.importMeta && options.importMeta.url)) {
throw new TypeError('The `importMeta` option is required. Its value must be `import.meta`.');
}
const foundPackage = readPackageUpSync({
cwd: dirname(fileURLToPath(options.importMeta.url)),
normalize: false

@@ -121,3 +121,3 @@ });

options = {
pkg: foundPkg ? foundPkg.packageJson : {},
pkg: foundPackage ? foundPackage.packageJson : {},
argv: process.argv.slice(2),

@@ -168,13 +168,13 @@ flags: {},

const {pkg} = options;
const {pkg: package_} = options;
const argv = parseArguments(options.argv, parserOptions);
let help = redent(trimNewlines((options.help || '').replace(/\t+\n*$/, '')), 2);
normalizePackageData(pkg);
normalizePackageData(package_);
process.title = pkg.bin ? Object.keys(pkg.bin)[0] : pkg.name;
process.title = package_.bin ? Object.keys(package_.bin)[0] : package_.name;
let {description} = options;
if (!description && description !== false) {
({description} = pkg);
({description} = package_);
}

@@ -190,3 +190,3 @@

const showVersion = () => {
console.log(typeof options.version === 'string' ? options.version : pkg.version);
console.log(typeof options.version === 'string' ? options.version : package_.version);
process.exit(0);

@@ -198,5 +198,3 @@ };

showVersion();
}
if (argv.help === true && options.autoHelp) {
} else if (argv.help === true && options.autoHelp) {
showHelp(0);

@@ -236,3 +234,3 @@ }

unnormalizedFlags,
pkg,
pkg: package_,
help,

@@ -244,2 +242,2 @@ showHelp,

module.exports = meow;
export default meow;
{
"name": "meow",
"version": "9.0.0",
"version": "10.0.0",
"description": "CLI app helper",

@@ -13,4 +13,6 @@ "license": "MIT",

},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=10"
"node": ">=12.17"
},

@@ -44,30 +46,27 @@ "scripts": {

"dependencies": {
"@types/minimist": "^1.2.0",
"@types/minimist": "^1.2.1",
"camelcase-keys": "^6.2.2",
"decamelize": "^1.2.0",
"decamelize": "^5.0.0",
"decamelize-keys": "^1.1.0",
"hard-rejection": "^2.1.0",
"minimist-options": "4.1.0",
"normalize-package-data": "^3.0.0",
"read-pkg-up": "^7.0.1",
"redent": "^3.0.0",
"trim-newlines": "^3.0.0",
"type-fest": "^0.18.0",
"yargs-parser": "^20.2.3"
"normalize-package-data": "^3.0.2",
"read-pkg-up": "^8.0.0",
"redent": "^4.0.0",
"trim-newlines": "^4.0.0",
"type-fest": "^1.0.2",
"yargs-parser": "^20.2.7"
},
"devDependencies": {
"ava": "^2.4.0",
"execa": "^4.1.0",
"indent-string": "^4.0.0",
"tsd": "^0.13.1",
"xo": "^0.34.1"
"ava": "^3.15.0",
"execa": "^5.0.0",
"indent-string": "^5.0.0",
"read-pkg": "^6.0.0",
"tsd": "^0.14.0",
"xo": "^0.39.1"
},
"xo": {
"rules": {
"unicorn/no-process-exit": "off",
"node/no-unsupported-features/es-syntax": "off"
},
"ignores": [
"estest/index.js"
]
"unicorn/no-process-exit": "off"
}
},

@@ -74,0 +73,0 @@ "ava": {

@@ -29,48 +29,7 @@ # meow

**CommonJS**
```js
#!/usr/bin/env node
'use strict';
const meow = require('meow');
const foo = require('.');
const cli = meow(`
Usage
$ foo <input>
Options
--rainbow, -r Include a rainbow
Examples
$ foo unicorns --rainbow
🌈 unicorns 🌈
`, {
flags: {
rainbow: {
type: 'boolean',
alias: 'r'
}
}
});
/*
{
input: ['unicorns'],
flags: {rainbow: true},
...
}
*/
foo(cli.input[0], cli.flags);
```
**ES Modules**
```js
#!/usr/bin/env node
import {createRequire} from 'module';
import meow from 'meow';
import foo from './lib/index.js';
const meow = createRequire(import.meta.url)('meow');
const cli = meow(`

@@ -87,2 +46,3 @@ Usage

`, {
importMeta: import.meta,
flags: {

@@ -131,2 +91,8 @@ rainbow: {

##### importMeta
Type: `object`
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.
##### flags

@@ -259,3 +225,3 @@

```js
const meow = require('meow');
const meow from 'meow';

@@ -275,2 +241,3 @@ const cli = meow(`

`, {
importMeta: import.meta,
booleanDefault: undefined,

@@ -277,0 +244,0 @@ flags: {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc