isStringSchema
Determines whether a given JSON schema represents a string type (nullable or non-nullable).
This is a combined filter that matches both { type: 'string' } and
{ type: ['string', 'null'] } schemas.
Signature
const isStringSchema: (schema: UnknownSchema) => schema is StringSchema
Parameters
| Name | Type | Description |
|---|---|---|
schema | - | The JSON schema object to inspect |
Returns
Type-safe boolean indicating whether the schema is a string schema (nullable or not)
Examples
Example 1
isStringSchema({ type: 'string' }); // true
isStringSchema({ type: ['string', 'null'] }); // true
isStringSchema({ type: 'number' }); // false
Playground
isStringSchema({ type: 'string' }); // true isStringSchema({ type: ['string', 'null'] }); // true isStringSchema({ type: 'number' }); // false