Function: string()
Call Signature
ts
export declare function string<const R extends boolean>(opts: StringOptions & {
required: R;
}): WithRequiredOption<CombinatorSchema<string>, R>Create a string argument schema with optional validation.
Type Parameters
| Name | Description |
|---|---|
R extends boolean | The type of required in the options, which the schema keeps. |
Parameters
| Name | Type | Description |
|---|---|---|
opts | StringOptions & { required: R } | Validation options. |
Returns
WithRequiredOption<CombinatorSchema<string>, R> — A combinator schema that resolves to string.
Examples
ts
const args = {
name: string({ minLength: 1, maxLength: 50 })
}Call Signature
ts
export declare function string<const R extends boolean | undefined = boolean | undefined>(opts?: StringOptions & {
required?: R;
}): WithUnrequiredOption<CombinatorSchema<string>, R>Create a string argument schema with optional validation.
Type Parameters
| Name | Description |
|---|---|
R extends boolean | undefined = boolean | undefined | The 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
| Name | Type | Description |
|---|---|---|
opts | StringOptions & { required?: R } | Validation options. (optional) |
Returns
WithUnrequiredOption<CombinatorSchema<string>, R> — A combinator schema that resolves to string.
Examples
ts
const args = {
name: string({ minLength: 1, maxLength: 50 })
}Call Signature
ts
export declare function string(opts?: StringOptions): CombinatorSchema<string>Create a string argument schema with optional validation.
Parameters
| Name | Type | Description |
|---|---|---|
opts | StringOptions | Validation options. (optional) |
Returns
CombinatorSchema<string> — A combinator schema that resolves to string.
Examples
ts
const args = {
name: string({ minLength: 1, maxLength: 50 })
}