-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextLog.js
35 lines (32 loc) · 879 Bytes
/
TextLog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const { DecoratedLog } = require("./DecoratedLog.js");
const { JsLog } = require("./JsLog.js");
/**
* @inheritDoc
*/
class TextLog extends DecoratedLog {
constructor(origin = new JsLog) {
super(origin);
}
asString() {
return '\n' + this.#recursiveFormatJsObjAsString( this.asJsObj() )
}
/**
* @param {Object} jsObj
* @param {String} tabs
* @returns {String}
*/
#recursiveFormatJsObjAsString(jsObj, tabs = '') {
let data = '';
for(let prop in jsObj) {
const val = jsObj[prop];
data += (tabs + prop);
if(typeof val === 'object') {
data += (':\n' + this.#recursiveFormatJsObjAsString(val, tabs + '\t'));
}
else
data += (': "' + val + '".\n');
}
return data;
}
}
module.exports = {TextLog};