validateArgspecfunction#
validateArgspec(spec: string): ValidateArgspecResultValidate an xparse-style argspec string and report its parsed slots.
Use it to self-check an argspec before injecting a custom command into a
Parser. Never throws on a malformed spec: the failure is reported
through the valid / error fields of the result. For the notation
semantics, see the Argspec guide.
| Parameter | Type | Description |
|---|---|---|
spec | string |
|
ValidateArgspecResult — A ValidateArgspecResult describing validity and slots.
import { validateArgspec } from 'texform';
validateArgspec('o m'); // { valid: true, error: null, argCount: 2, parsed: [ ... ] }
validateArgspec('ABC123').valid; // falseValidateArgspecResultinterface#
The outcome of validateArgspec: whether the spec is well-formed and, when valid, its parsed slots.
On success valid is true and argCount / parsed describe the slots; on
failure valid is false and error carries the reason.
| Field | Type | Description |
|---|---|---|
valid | boolean | Whether the specification parsed successfully. |
error | string | | The error message when invalid, otherwise |
argCount | number | | The number of argument slots when valid, otherwise |
parsed | Parsed | The per-slot breakdown when valid, otherwise |
ParsedArgSpecSlotinterface#
One parsed argument slot of an argspec, as reported by validateArgspec and by the parser's command/environment lookups.
| Field | Type | Description |
|---|---|---|
required | boolean | Whether the argument is mandatory ( |
noLeadingSpace | boolean | Whether leading space before the argument is disallowed. |
nullable | boolean | Whether an absent optional argument yields a null value. |
kind | Arg | The value kind the slot accepts. |
form | Arg | The syntactic form the slot takes. |