# validateArgspec

Validate an argspec string and inspect the parsed argument slots.

https://texform.dev/api/js/validate-argspec

## `validateArgspec`

Kind: function

```ts
validateArgspec(spec: string): ValidateArgspecResult
```

Validate 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](/api/js/parser#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.

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `spec` | string | — | - The argspec string, such as `'o m'`, `'s m{}'`, or
`` `d<(,)><[,]>` ``. |

**Returns** `ValidateArgspecResult` A [ValidateArgspecResult](/api/js/validate-argspec#ValidateArgspecResult) describing validity and slots.

```ts
import { validateArgspec } from 'texform';

validateArgspec('o m'); // { valid: true, error: null, argCount: 2, parsed: [ ... ] }
validateArgspec('ABC123').valid; // false
```

- [Parser](https://texform.dev/api/js/parser.md#Parser)
- [Argspec](https://texform.dev/docs/argspec.md)
- [ValidateArgspecResult](https://texform.dev/api/js/validate-argspec.md#ValidateArgspecResult)

## `ValidateArgspecResult`

Kind: interface

The outcome of [validateArgspec](/api/js/validate-argspec#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.

| Name | Type | Description |
| --- | --- | --- |
| `valid` | boolean | Whether the specification parsed successfully. |
| `error` | string | null | The error message when invalid, otherwise `null`. |
| `argCount` | number | null | The number of argument slots when valid, otherwise `null`. |
| `parsed` | ParsedArgSpecSlot[] | null | The per-slot breakdown when valid, otherwise `null`. |

- [validateArgspec](https://texform.dev/api/js/validate-argspec.md#validateArgspec)

## `ParsedArgSpecSlot`

Kind: interface

One parsed argument slot of an argspec, as reported by
[validateArgspec](/api/js/validate-argspec#validateArgspec) and by the parser's command/environment lookups.

| Name | Type | Description |
| --- | --- | --- |
| `required` | boolean | Whether the argument is mandatory (`true`) or optional (`false`). |
| `noLeadingSpace` | boolean | Whether leading space before the argument is disallowed. |
| `nullable` | boolean | Whether an absent optional argument yields a null value. |
| `kind` | ArgSpecKindInfo | The value kind the slot accepts. |
| `form` | ArgSpecFormInfo | The syntactic form the slot takes. |

- [validateArgspec](https://texform.dev/api/js/validate-argspec.md#validateArgspec)

