Aller au contenu principal

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";'