generateMultipleOfCheck()
generateMultipleOfCheck(
varName,divisor,ctx,customMessage?):CodeGenResult
Experimental
Generates inline code for the multipleOf constraint.
Uses modulo operation to check if value is a multiple of the given divisor. Handles floating point precision issues by using a small epsilon for comparison.
Parametersโ
varName: stringโ
The variable name to check
divisor: numberโ
The value that the number must be a multiple of
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 = generateMultipleOfCheck("value", 5, ctx);
// result.code = 'if (value % 5 !== 0) return "Number must be a multiple of 5";'