Comprehensive boolean validation plugin for Flatfile that handles various representations of boolean values with multi-language support and flexible configuration options.
true
and false
. Key features include two main validation modes: ‘strict’ (only accepts true/false boolean types) and ‘truthy’ (accepts values like ‘yes’, ‘no’, ‘y’, ‘n’, etc.). The plugin offers multi-language support for these truthy values (English, Spanish, French, German) and allows for custom mappings. It is highly configurable, with options to control case sensitivity, how null/undefined values are handled, and whether to automatically convert non-boolean values.
BooleanValidatorConfig
, containing the following options:
fields
string[]
validationType
'strict' | 'truthy'
'strict'
: Only allows true
and false
boolean values'truthy'
: Allows string representations like ‘yes’, ‘no’, etc.sheetSlug
string
'**'
(all sheets)language
'en' | 'es' | 'fr' | 'de'
'en'
customMapping
Record<string, boolean>
{ 'ja': true, 'nein': false }
caseSensitive
boolean
false
handleNull
'error' | 'false' | 'true' | 'skip'
null
or undefined
values:
'error'
: Adds an error to the record'false'
: Converts the value to false
'true'
: Converts the value to true
'skip'
: Ignores the value without adding an error'skip'
convertNonBoolean
boolean
Boolean()
castingfalse
defaultValue
boolean | 'skip'
undefined
(raises an error)customErrorMessages
object
invalidBoolean
, invalidTruthy
, nullValue
config
- Configuration object for the validatorlistener.use()
to register the plugin.
value
- The value to validateconfig
- The configuration objectvalue
(validated boolean or null) and error
(error message or null)
true
or false
.
Signature:
null
or undefined
value according to the handleNull
configuration.
Signature:
fields
array contains the correct field keyssheetSlug
(if used) matches the target sheetcaseSensitive
option. It defaults to false
, but if set to true
, the case must match exactly.
defaultValue
is used as a final fallback for invalid valuesfields
and validationType
options are provided, the plugin will apply validation to the specified fields on all sheets. For ‘truthy’ validation, it uses case-insensitive English mappings (‘yes’/‘no’). Null or undefined values are skipped by default.
customMapping
) take precedence over language-based default mappingssheetSlug
option allows applying different validation rules to different sheets within the same workbookdefaultValue
is provided, the plugin corrects invalid values and adds an informational message for auditing{ value, error }
object pattern for easy error checking