A Flatfile plugin for boolean validation with multi-language support
npm i @flatfile/plugin-validate-boolean
The @flatfile/plugin-validate-boolean
plugin provides comprehensive boolean validation capabilities, offering flexible configuration options to handle various boolean representations across different languages and use cases.
Event Type:
listener.on('commit:created')
To install the plugin, run the following command:
npm install @flatfile/plugin-validate-boolean
import { validateBoolean } from '@flatfile/plugin-validate-boolean';
listener.use(
validateBoolean({
fields: ['isActive', 'hasSubscription'],
validationType: 'truthy',
language: 'en',
handleNull: 'false',
convertNonBoolean: true
}
));
The BooleanValidator
function accepts a configuration object with the following properties:
fields
: An array of field names to validatevalidationType
: 'strict' or 'truthy'customMapping
: A custom mapping of string values to booleancaseSensitive
: Whether the validation should be case-sensitivehandleNull
: How to handle null values ('error', 'false', 'true', or 'skip')convertNonBoolean
: Whether to convert non-boolean values to booleanlanguage
: The language for predefined mappings ('en', 'es', 'fr', 'de')customErrorMessages
: Custom error messages for different scenariosdefaultValue
: A default value to use for invalid inputsThe plugin can be used either as a RecordHook or as an external constraint, providing flexibility in integration with your Flatfile setup.