UNPKG

quantique-converter

Version:
20 lines (18 loc) 521 B
// Convert to Number const convertToNumber = (input) => { if (typeof input === 'boolean') { return { isValid: true, error: '', convertedValue: input ? 1 : 0 }; } const num = Number(input); if (isNaN(num)) { return { isValid: false, error: `Cannot convert ${input} to number` || defaultErrorMessages(rules, type).minLength, convertedValue: '', }; } return { isValid: true, error: '', convertedValue: num }; }; module.exports = convertToNumber;