From 0a0eb4c718f742844bab10234132dd1e44107825 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Monda?= Date: Sun, 3 Apr 2016 21:10:41 +0200 Subject: [PATCH] Chop off the tail of overly long JSONs. --- config-serializer/Serializable.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/config-serializer/Serializable.ts b/config-serializer/Serializable.ts index 7f7b20d0..647dc973 100644 --- a/config-serializer/Serializable.ts +++ b/config-serializer/Serializable.ts @@ -5,11 +5,19 @@ interface Function { abstract class Serializable { private static depth = 0; + private static maxDisplayedJsonLength = 160; + + strintifyJsObject(jsObject: any): string { + let json = JSON.stringify(jsObject); + return json.length > Serializable.maxDisplayedJsonLength + ? json.substr(0, Serializable.maxDisplayedJsonLength) + '...' + : json; + } fromJsObject(jsObject: any): T { let indentation = new Array(Serializable.depth + 1).join(' '); let isArray = this instanceof UhkArray; - process.stdout.write(`${indentation}${this.constructor.name}.fromJsObject: ${JSON.stringify(jsObject)}` + (isArray ? '\n' : ` => `)); + process.stdout.write(`${indentation}${this.constructor.name}.fromJsObject: ${this.strintifyJsObject(jsObject)}` + (isArray ? '\n' : ` => `)); Serializable.depth++; let value = this._fromJsObject(jsObject); Serializable.depth--; @@ -42,7 +50,7 @@ abstract class Serializable { let value = this._toJsObject(); Serializable.depth--; if (!isArray) { - process.stdout.write(`${JSON.stringify(value)}\n`); + process.stdout.write(`${this.strintifyJsObject(value)}\n`); } return value; }