quantique-converter
Version:
Converters for all kind of data
14 lines (13 loc) • 505 B
JavaScript
// Convert to Object
const convertToObject = (input) => {
if (typeof input === 'object' && !Array.isArray(input)) return { isValid: true, error: '', convertedValue: input };
if (typeof input === 'string') {
try {
return { isValid: true, error: '', convertedValue: JSON.parse(input) };
} catch (e) {
return { isValid: true, error: '', convertedValue: input };
}
}
return { isValid: true, error: '', convertedValue: input };
};
module.exports = convertToObject;