commit:created listener event to analyze and validate data from specified fields.
Its main purpose is to ensure that numeric data conforms to a wide range of rules before being accepted into the system. Use cases include:
- Enforcing value ranges (e.g., age must be between 18 and 65)
- Validating data formats like integers, currency, or numbers with specific precision and scale
- Ensuring numbers follow specific rules, such as being a multiple of a certain value (step validation)
- Checking for special numeric properties like being even, odd, or prime
- Automatically cleaning up number formats by handling thousands separators and decimal points
- Optionally rounding or truncating numbers before validation
Installation
Install the plugin using npm:Configuration & Parameters
ThevalidateNumber function accepts a single configuration object with the following properties:
Required Parameters
Optional Parameters
Usage Examples
Basic Usage
Currency Validation
Direct Validation Function
API Reference
validateNumber
The main plugin entry point that returns a function for use withlistener.use().
Parameters:
config(object): Configuration object containing validation rules and target fields
(listener: FlatfileListener) => void that registers the validation hook.
Example:
validateNumberField
A standalone utility function that validates a single value against validation rules. Parameters:value(string | number): The input value to validateconfig(NumberValidationConfig): Configuration object with validation rules
NumberValidationResult object with:
value(number | null): The parsed numeric value or null if parsing failederrors(string[]): Array of error messages for fundamental parsing failureswarnings(string[]): Array of warning messages for validation rule violations
isPrime
A helper function to check if a number is prime. Used internally whenspecialTypes: ['prime'] is configured.
Parameters:
num(number): The number to check
boolean - True if the number is prime, false otherwise
Troubleshooting
- Validation not working: Check the
fieldsandsheetSlugconfiguration to ensure the plugin is targeting the correct data - Unexpected number formats: Verify the
thousandsSeparatoranddecimalPointsettings match your data format - Reference examples: The test file
src/validate.number.plugin.spec.tsprovides clear examples of expected outcomes for every configuration option
Notes
Default Behavior
- The
min/maxvalidation is exclusive by default. To include boundary values, setinclusive: true - Default
thousandsSeparatoris','anddecimalPointis'.' - If both
roundandtruncateare true, rounding occurs first, then truncation
Special Considerations
- The plugin operates on the
commit:createdevent, running after user submission but before data finalization - The plugin modifies
FlatfileRecordin place, overwriting original values with parsed numeric values - Fundamental parsing failures (e.g., “abc” as a number) result in “errors”
- Rule violations (e.g., number outside min/max range) result in “warnings”
- The plugin follows standard Flatfile patterns by adding errors/warnings to records rather than throwing exceptions

