Skip to main content

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
// ]