From 842627d6b905f71aea821c426a886022b07270a5 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 19 Mar 2019 13:52:25 -0400 Subject: pretty-print long strings --- js/console.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'js/console.ts') diff --git a/js/console.ts b/js/console.ts index bde912dd6..b68794d3f 100644 --- a/js/console.ts +++ b/js/console.ts @@ -23,6 +23,8 @@ const DEFAULT_MAX_DEPTH = 4; // form. const OBJ_ABBREVIATE_SIZE = 5; +const STR_ABBREVIATE_SIZE = 100; + // Char codes const CHAR_PERCENT = 37; /* % */ const CHAR_LOWERCASE_S = 115; /* s */ @@ -151,7 +153,11 @@ function stringifyWithQuotes( ): string { switch (typeof value) { case "string": - return `"${value}"`; + const trunc = + value.length > STR_ABBREVIATE_SIZE + ? value.slice(0, STR_ABBREVIATE_SIZE) + "..." + : value; + return JSON.stringify(trunc); default: return stringify(value, ctx, level, maxLevel); } -- cgit v1.2.3