Function: combinator()
Call Signature
export declare function combinator<T, const R extends boolean>(config: CombinatorOptions<T> & {
required: R;
}): WithRequiredOption<CombinatorSchema<T>, R>Create a custom argument schema with a user-defined parse function.
This is the most general custom combinator. Use it when none of the built-in base combinators (string, number, integer, float, boolean, choice) fit your needs.
The returned schema has type: 'custom'.
Type Parameters
| Name | Description |
|---|---|
T | The parsed value type. |
R extends boolean | The type of required in the configuration, which the schema keeps. |
Parameters
| Name | Type | Description |
|---|---|---|
config | CombinatorOptions<T> & { required: R } | Configuration with a parse function and optional metavar. |
Returns
WithRequiredOption<CombinatorSchema<T>, R> — A combinator schema that resolves to the parse function's return type.
Examples
const date = combinator({
parse: (value) => {
const d = new Date(value)
if (isNaN(d.getTime())) {
throw new Error('Invalid date format')
}
return d
},
metavar: 'date'
})Call Signature
export declare function combinator<T, const R extends boolean | undefined = boolean | undefined>(config: CombinatorOptions<T> & {
required?: R;
}): WithUnrequiredOption<CombinatorSchema<T>, R>Create a custom argument schema with a user-defined parse function.
This is the most general custom combinator. Use it when none of the built-in base combinators (string, number, integer, float, boolean, choice) fit your needs.
The returned schema has type: 'custom'.
Type Parameters
| Name | Description |
|---|---|
T | The parsed value type. |
R extends boolean | undefined = boolean | undefined | The type of required in the configuration, 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
| Name | Type | Description |
|---|---|---|
config | CombinatorOptions<T> & { required?: R } | Configuration with a parse function and optional metavar. |
Returns
WithUnrequiredOption<CombinatorSchema<T>, R> — A combinator schema that resolves to the parse function's return type.
Examples
const date = combinator({
parse: (value) => {
const d = new Date(value)
if (isNaN(d.getTime())) {
throw new Error('Invalid date format')
}
return d
},
metavar: 'date'
})Call Signature
export declare function combinator<T>(config: CombinatorOptions<T>): CombinatorSchema<T>Create a custom argument schema with a user-defined parse function.
This is the most general custom combinator. Use it when none of the built-in base combinators (string, number, integer, float, boolean, choice) fit your needs.
The returned schema has type: 'custom'.
Type Parameters
| Name | Description |
|---|---|
T | The parsed value type. |
Parameters
| Name | Type | Description |
|---|---|---|
config | CombinatorOptions<T> | Configuration with a parse function and optional metavar. |
Returns
CombinatorSchema<T> — A combinator schema that resolves to the parse function's return type.
Examples
const date = combinator({
parse: (value) => {
const d = new Date(value)
if (isNaN(d.getTime())) {
throw new Error('Invalid date format')
}
return d
},
metavar: 'date'
})