function formatConfig(config) {
let output = "";
for (const key in config) {
if (config.hasOwnProperty(key)) {
const value = config[key];
let formattedValue;
if (typeof value === 'string') {
formattedValue = `"${value}"`; // Wrap strings in double quotes
} else if (typeof value === 'number') {
formattedValue = value.toFixed(2); // Format numbers to 2 decimal places
} else if (typeof value === 'boolean') {
formattedValue = value ? "true" : "false"; //Represent boolean as string
} else if (value === null) {
formattedValue = "null"; // Represent null as string
} else if (typeof value === 'object') {
formattedValue = JSON.stringify(value, null, 2); //Pretty print objects
}
else {
formattedValue = String(value); //Convert other types to string
}
output += ` ${key}: ${formattedValue}\n`; // Add key-value pair to output
}
}
return output;
}
Add your comment