generatePropertyValidation()
generatePropertyValidation(
objectVar,prop,ctx):object
Experimental
Generates code to extract and validate a single property.
Parameters
objectVar: string
The variable name of the object
prop: ObjectPropertyMeta
The property metadata
ctx: GeneratorContext
The generator context
Returns: object
Generated code lines and updated context
code: string[]
ctx: GeneratorContext
Since
2.0.0
Example
const result = generatePropertyValidation("value", { name: "age", optional: false }, ctx);
// result.code = [
// 'var v_0 = value["age"];',
// 'if (v_0 === undefined) return "Property \'age\': Required";',
// // ... property type validation
// ]