From a14d16457add16eee5d2a3babcb1ebf558bd8516 Mon Sep 17 00:00:00 2001 From: qinjia Date: Fri, 6 Nov 2015 17:32:33 +0800 Subject: [PATCH] util: use regexp instead of str.replace().join() PR-URL: https://github.com/nodejs/node/pull/3689 Reviewed-By: Colin Ihrig Reviewed-By: Jeremiah Senkpiel Reviewed-By: James M Snell --- lib/util.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/util.js b/lib/util.js index 399a4ee0a23828..a6231c8acf56da 100644 --- a/lib/util.js +++ b/lib/util.js @@ -575,13 +575,9 @@ function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { } if (str.indexOf('\n') > -1) { if (array) { - str = str.split('\n').map(function(line) { - return ' ' + line; - }).join('\n').substr(2); + str = str.replace(/\n/g, '\n '); } else { - str = '\n' + str.split('\n').map(function(line) { - return ' ' + line; - }).join('\n'); + str = str.replace(/(^|\n)/g, '\n '); } } } else {