MCPcopy Index your code
hub / github.com/processing/p5.js / generateParamSchema

Function generateParamSchema

src/core/friendly_errors/param_validator.js:225–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

223 // Generate a schema for a single parameter. In the case where a parameter can
224 // be of multiple types, `generateTypeSchema` is called for each type.
225 const generateParamSchema = param => {
226 const isOptional = param?.endsWith('?');
227 param = param?.replace(/\?$/, '');
228
229 const isRest = param?.startsWith('...') && param?.endsWith('[]');
230 param = param?.replace(/^\.\.\.(.+)\[\]$/, '$1');
231
232 let schema = generateTypeSchema(param);
233 // Fallback to z.custom() because function types are no longer
234 // returns a Zod schema.
235 if (schema.def.type === 'function') {
236 schema = z.custom(val => val instanceof Function);
237 }
238
239 if (isOptional) {
240 schema = schema.optional();
241 }
242 return { schema, rest: isRest };
243 };
244
245 // Note that in Zod, `optional()` only checks for undefined, not the absence
246 // of value.

Callers 1

Calls 1

generateTypeSchemaFunction · 0.85

Tested by

no test coverage detected