MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / parseResultJsonWithZodSchema

Function parseResultJsonWithZodSchema

apps/web/src/lib/utils.ts:191–221  ·  view source on GitHub ↗
(
  response: Response,
  schema: ZodType<T>
)

Source from the content-addressed store, hash-verified

189/**
190 * Converts the first character of a string to uppercase.
191 * Note: This is NOT full title-casing (e.g., "hello world" → "Hello world", not "Hello World")
192 */
193export function capitalize(s: string): string {
194 return s.charAt(0).toUpperCase() + s.slice(1);
195}
196
197/**
198 * Asserts that a value is not null or undefined and narrows its type.
199 * Throws an error if the value is null or undefined.
200 * This version provides type narrowing of the original parameter.
201 *
202 * @param value - The value to check for null/undefined
203 * @param message - Optional custom error message
204 * @throws Error if the value is null or undefined
205 */
206export function assertNotNullish<T>(value: T, message?: string): asserts value is NonNullable<T> {
207 if (value === null || value === undefined) {
208 throw new Error(message || 'Value must not be null or undefined');
209 }
210}
211
212/**
213 * Asserts that a value is not null or undefined and returns it with proper type narrowing.
214 * Throws an error if the value is null or undefined.
215 * This version returns the non-null value for use in expressions.
216 *
217 * @param value - The value to check for null/undefined
218 * @param message - Optional custom error message
219 * @returns The value with null and undefined removed from its type
220 * @throws Error if the value is null or undefined
221 */
222export function toNonNullish<T>(value: T, message?: string): NonNullable<T> {
223 assertNotNullish(value, message);
224 return value;

Callers 1

utils.test.tsFile · 0.90

Calls 1

jsonMethod · 0.65

Tested by

no test coverage detected