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

Function validateParams

src/core/friendly_errors/param_validator.js:8–630  ·  view source on GitHub ↗
(p5, fn, lifecycles)

Source from the content-addressed store, hash-verified

6import dataDoc from '../../../docs/parameterData.json';
7
8function validateParams(p5, fn, lifecycles) {
9 // Cache for Zod schemas
10 let schemaRegistry = new Map();
11
12 // Mapping names of p5 types to their constructor functions.
13 // p5Constructors:
14 // - Color: f()
15 // - Graphics: f()
16 // - Vector: f()
17 // and so on.
18 // const p5Constructors = {};
19 // NOTE: This is a tempt fix for unit test but is not correct
20 // Attaced constructors are `undefined`
21 const p5Constructors = Object.keys(p5).reduce((acc, val) => {
22 if (
23 val.match(/^[A-Z]/) && // Starts with a capital
24 !val.match(/^[A-Z][A-Z0-9]*$/) && // Is not an all caps constant
25 p5[val] instanceof Function // Is a function
26 ) {
27 acc[val] = p5[val];
28 }
29 return acc;
30 }, {});
31
32 function loadP5Constructors() {
33 // Make a list of all p5 classes to be used for argument validation
34 // This must be done only when everything has loaded otherwise we get
35 // an empty array
36 for (let key of Object.keys(p5)) {
37 // Get a list of all constructors in p5. They are functions whose names
38 // start with a capital letter
39 if (typeof p5[key] === 'function' && key[0] !== key[0].toLowerCase()) {
40 p5Constructors[key] = p5[key];
41 }
42 }
43 }
44
45 // `constantsMap` maps constants to their values, e.g.
46 // {
47 // ADD: 'lighter',
48 // ALT: 18,
49 // ARROW: 'default',
50 // AUTO: 'auto',
51 // ...
52 // }
53 const constantsMap = {};
54 for (const [key, value] of Object.entries(constants)) {
55 constantsMap[key] = value;
56 }
57
58 // Start initializing `schemaMap` with primitive types. `schemaMap` will
59 // eventually contain both primitive types and web API objects.
60 const schemaMap = {
61 'Any': z.any(),
62 'Array': z.array(z.any()),
63 'Boolean': z.boolean(),
64 'Function': z.function(),
65 'Integer': z.number().int(),

Callers 1

param_errors.jsFile · 0.85

Calls 6

generateWebAPISchemasFunction · 0.85
validateFunction · 0.85
loadP5ConstructorsFunction · 0.85
registerDecoratorMethod · 0.80
arrayMethod · 0.45
applyMethod · 0.45

Tested by

no test coverage detected