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 ; parse?: Parser<ArgsObject, number> ; array?: boolean ; required?: boolean ; isDefault?: boolean ; hidden?: boolean ; outputName?: string }, "parse">

Returns​

MassargNumber

Overrides​

MassargOption.constructor

Defined in​

src/option.ts:302

Properties​

name​

• name: string

Inherited from​

MassargOption.name

Defined in​

src/option.ts:175


description​

• description: string

Inherited from​

MassargOption.description

Defined in​

src/option.ts:176


defaultValue​

• Optional defaultValue: number

Inherited from​

MassargOption.defaultValue

Defined in​

src/option.ts:177


aliases​

• aliases: string[]

Inherited from​

MassargOption.aliases

Defined in​

src/option.ts:178


parse​

• parse: Parser<ArgsObject, number>

Inherited from​

MassargOption.parse

Defined in​

src/option.ts:179


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:184


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:186


isDefault​

• isDefault: boolean

Inherited from​

MassargOption.isDefault

Defined in​

src/option.ts:187


outputName​

• Optional outputName: string

Inherited from​

MassargOption.outputName

Defined in​

src/option.ts:188

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​

NameTypeDescription
configObject-
config.namestringName of the option
config.descriptionstringDescription of the option, displayed in the help output
config.aliasesstring[]Aliases for the option, which can be used with the shorthand option notation.
config.defaultValue?anyDefault value of the option
config.parse?Parser<A, T>Parse the value of the option. You can return any type here, or throw an error if the value is invalid.
config.array?booleanWhether the option is an array. Array options can be specified multiple times, and the values will be collected into an array. Normally, specifying an option multiple times will override the previous value.
config.required?booleanWhether the option is required. If it is required, parsing will throw an error if it's not present.
config.isDefault?booleanWhether the option is the default option. The default option is the option that is used if no other option is specified, e.g. a value is passed in without an option name. Note that if commands match the same argument first, they will be used instead of the default option.
config.hidden?booleanWhether the option is hidden. Hidden options are not displayed in the help output.
config.outputName?stringSpecify a custom name for the output, which will be used when parsing the args.
config.type?"number"-

Returns​

MassargOption<T, ArgsObject>

Inherited from​

MassargOption.fromTypedConfig

Defined in​

src/option.ts:207


parseDetails​

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

Parameters​

NameType
argvstring[]
optionsArgsObject
prefixesPrefixes

Returns​

ArgvValue<number>

Overrides​

MassargOption.parseDetails

Defined in​

src/option.ts:309


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:224


helpString​

▸ helpString(): string

Get the help string for this option

Returns​

string

Inherited from​

MassargOption.helpString

Defined in​

src/option.ts:258


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:264


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:275