generateCoerceNumberCheck()
generateCoerceNumberCheck(
varName,ctx,customMessage?):CodeGenResult
Experimental
Generates inline code for coerce.number().
If the value is already a valid number (not NaN), returns true.
Otherwise, converts to number using Number(value) with NaN check.
Returns { coerced: result } for successful coercions.
Parameters
varName: string
The variable name to coerce
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 = generateCoerceNumberCheck("value", ctx);
// Generated code handles:
// - Already a number: return true
// - Boolean: coerce to 0/1
// - Empty string: coerce to 0
// - Other: try Number(value) with NaN check