Fakultas Ilmu Komputer UI

Commit 9481a574 authored by Zamil Majdy's avatar Zamil Majdy
Browse files

[Implementation] Add dumper library

parent 7db7f714
......@@ -2,6 +2,24 @@
export default class Dumper {
static dump(obj, indent) {
let result = '';
for (const property in obj) {
let value = obj[property];
if (typeof value === 'string') {
value = `${value}`;
} else if (typeof value === 'object') {
if (value instanceof Array) {
// Just let JS convert the Array to a string!
value = `[ ${value} ]`;
} else {
const od = this.dump(value, `${indent} `);
value = `\n${od}`;
}
}
result += `${indent}${property} : ${value},\n`;
}
return result.replace(/,\n$/, '');
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment