Skip to main content

generatePositiveCheck()

generatePositiveCheck(varName, ctx, customMessage?): CodeGenResult

Experimental

Generates inline code for the positive constraint (value > 0).


Parametersโ€‹

varName: stringโ€‹

The variable name to check

ctx: GeneratorContextโ€‹

The generator context

customMessage?: stringโ€‹

Optional custom error message


Returns: CodeGenResultโ€‹

Generated code and updated context


Sinceโ€‹

2.0.0


Exampleโ€‹

const result = generatePositiveCheck("value", ctx);
// result.code = 'if (value <= 0) return "Number must be positive";'