Skip to content

Function: boolean() ​

Call Signature ​

ts
export declare function boolean<const R extends boolean>(opts: BooleanOptions & {
  required: R;
}): WithRequiredOption<CombinatorSchema<boolean>, R>

Create a boolean argument schema.

Boolean arguments are existence-based. The resolver passes "true" or "false" to the parse function based on the presence or negation of the flag, or on an explicit =true / =false value. Other inline values are rejected before the parse function is called.

Type Parameters ​

NameDescription
R extends booleanThe type of required in the options, which the schema keeps.

Parameters ​

NameTypeDescription
optsBooleanOptions & { required: R }Boolean options.

Returns ​

WithRequiredOption<CombinatorSchema<boolean>, R> — A combinator schema for boolean flags.

Examples ​

ts
const args = {
  color: boolean({ negatable: true })
}
// Usage: --color (true), --no-color (false)

Call Signature ​

ts
export declare function boolean<const R extends boolean | undefined = boolean | undefined>(opts?: BooleanOptions & {
  required?: R;
}): WithUnrequiredOption<CombinatorSchema<boolean>, R>

Create a boolean argument schema.

Boolean arguments are existence-based. The resolver passes "true" or "false" to the parse function based on the presence or negation of the flag, or on an explicit =true / =false value. Other inline values are rejected before the parse function is called.

Type Parameters ​

NameDescription
R extends boolean | undefined = boolean | undefinedThe type of required in the options, which the schema keeps when it may be false but not true, as for optional ? { required: false } : {}, so that a positional argument with it is optional.

Parameters ​

NameTypeDescription
optsBooleanOptions & { required?: R }Boolean options. (optional)

Returns ​

WithUnrequiredOption<CombinatorSchema<boolean>, R> — A combinator schema for boolean flags.

Examples ​

ts
const args = {
  color: boolean({ negatable: true })
}
// Usage: --color (true), --no-color (false)

Call Signature ​

ts
export declare function boolean(opts?: BooleanOptions): CombinatorSchema<boolean>

Create a boolean argument schema.

Boolean arguments are existence-based. The resolver passes "true" or "false" to the parse function based on the presence or negation of the flag, or on an explicit =true / =false value. Other inline values are rejected before the parse function is called.

Parameters ​

NameTypeDescription
optsBooleanOptionsBoolean options. (optional)

Returns ​

CombinatorSchema<boolean> — A combinator schema for boolean flags.

Examples ​

ts
const args = {
  color: boolean({ negatable: true })
}
// Usage: --color (true), --no-color (false)

Released under the MIT License.