ai-functions
Version:
Core AI primitives for building intelligent applications
29 lines • 752 B
JavaScript
/**
* Type Guards for AI Functions
*
* Shared type guard utilities used across AI packages.
*
* @packageDocumentation
*/
/**
* Check if value is a Zod schema
*
* Uses duck-typing to detect Zod schemas by checking for the
* `_def` property (internal Zod schema definition) and `parse` method.
*
* @example
* ```ts
* import { isZodSchema } from 'ai-functions'
* import { z } from 'zod'
*
* const schema = z.object({ name: z.string() })
* if (isZodSchema(schema)) {
* // TypeScript knows schema is ZodTypeAny
* schema.parse({ name: 'test' })
* }
* ```
*/
export function isZodSchema(value) {
return value !== null && typeof value === 'object' && '_def' in value && 'parse' in value;
}
//# sourceMappingURL=type-guards.js.map