quantique-converter
Version:
Converters for all kind of data
13 lines (12 loc) • 596 B
JavaScript
// Convert to Boolean
const convertToBoolean = (input) => {
if (typeof input === 'string') {
const lower = input.toLowerCase();
if (lower === 'true') return { isValid: true, error: '', convertedValue: true };
if (lower === 'false') return { isValid: true, error: '', convertedValue: false };
if (lower === '1') return { isValid: true, error: '', convertedValue: true };
if (lower === '0') return { isValid: true, error: '', convertedValue: false };
}
return { isValid: true, error: '', convertedValue: Boolean(input) };
};
module.exports = convertToBoolean;