16 lines
434 B
TypeScript
16 lines
434 B
TypeScript
const formatDictionaryAsString = (obj: any, indentation = 2) => {
|
|
let result: string = "{\n";
|
|
for (let key in obj) {
|
|
if (obj.hasOwnProperty(key)) {
|
|
let value = obj[key];
|
|
let line = ' '.repeat(indentation) + `${key}: '${value}',\n`;
|
|
result += line;
|
|
}
|
|
}
|
|
result = result.slice(0, -2);
|
|
result += `\n}`;
|
|
return result;
|
|
}
|
|
|
|
export default formatDictionaryAsString;
|