Skip to main content

generateIntCheck()

generateIntCheck(varName, ctx, customMessage?): CodeGenResult

Experimental

Generates inline code for the integer constraint.


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 = generateIntCheck("value", ctx);
// result.code = 'if (!Number.isInteger(value)) return "Number must be an integer";'