Skip to main content

Class: MassargNumber

option.MassargNumber

An option that can be passed to a command.

This type of option parses a number, and fails if it is not a valid number.

Example

massarg(options).option({
name: 'number',
description: 'A number',
defaultValue: 0,
aliases: ['n'],
type: 'number',
})

Hierarchy

Constructors

constructor

new MassargNumber(options): MassargNumber

Parameters

NameType
optionsOmit<{ name: string ; description: string ; aliases: string[] ; defaultValue?: any ; array?: boolean ; required?: boolean ; isDefault?: boolean ; hidden?: boolean ; outputName?: string ; parse?: Parser<ArgsObject, number> }, "parse">

Returns

MassargNumber

Overrides

MassargOption.constructor

Defined in

src/option.ts:304

Properties

name

name: string

Inherited from

MassargOption.name

Defined in

src/option.ts:177


description

description: string

Inherited from

MassargOption.description

Defined in

src/option.ts:178


defaultValue

Optional defaultValue: number

Inherited from

MassargOption.defaultValue

Defined in

src/option.ts:179


aliases

aliases: string[]

Inherited from

MassargOption.aliases

Defined in

src/option.ts:180


parse

parse: Parser<ArgsObject, number>

Inherited from

MassargOption.parse

Defined in

src/option.ts:181


isArray

isArray: boolean

Whether this option can be used multiple times. Any passed values will end up in an array instead of each usage overwriting the existing value.

Inherited from

MassargOption.isArray

Defined in

src/option.ts:186


isRequired

isRequired: boolean

Whether this option is required. Failing to specify this option will throw an error.

Inherited from

MassargOption.isRequired

Defined in

src/option.ts:188


isDefault

isDefault: boolean

Inherited from

MassargOption.isDefault

Defined in

src/option.ts:189


outputName

Optional outputName: string

Inherited from

MassargOption.outputName

Defined in

src/option.ts:190

Methods

fromTypedConfig

fromTypedConfig<T, A>(config): MassargOption<T, ArgsObject>

Create a typed option from a configuration. Currently supports number options which are automatically transformed from string to number.

Type parameters

NameType
Tunknown
Aextends ArgsObject = ArgsObject

Parameters

NameType
configObject
config.namestring
config.descriptionstring
config.aliasesstring[]
config.typeundefined | "number"
config.defaultValueany
config.arrayundefined | boolean
config.requiredundefined | boolean
config.isDefaultundefined | boolean
config.hiddenundefined | boolean
config.outputNameundefined | string
config.parseundefined | Parser<A, T>

Returns

MassargOption<T, ArgsObject>

Inherited from

MassargOption.fromTypedConfig

Defined in

src/option.ts:209


parseDetails

parseDetails(argv, options, prefixes): ArgvValue<number>

Parameters

NameType
argvstring[]
optionsArgsObject
prefixesPrefixes

Returns

ArgvValue<number>

Overrides

MassargOption.parseDetails

Defined in

src/option.ts:311


getOutputName

getOutputName(): string

Returns the key which this option outputs to in the final object.

Returns

string

Default

The camelCase version of this option's name.

Can be overridden with {@link outputName}.

Inherited from

MassargOption.getOutputName

Defined in

src/option.ts:226


helpString

helpString(): string

Get the help string for this option

Returns

string

Inherited from

MassargOption.helpString

Defined in

src/option.ts:260


isMatch

isMatch(arg, prefixes): boolean

Returns true if the flag (including any prefixes) matches the name or aliases

Parameters

NameType
argstring
prefixesPrefixes

Returns

boolean

Inherited from

MassargOption.isMatch

Defined in

src/option.ts:266


qualifiedNames

qualifiedNames(prefixes): QualifiedNames

Return the finalized names that will cause this option to match.

Parameters

NameType
prefixesPrefixes

Returns

QualifiedNames

Inherited from

MassargOption.qualifiedNames

Defined in

src/option.ts:277