Skip to content

Commit

Permalink
feat: improve new lines representation
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Aug 18, 2017
1 parent 6842d06 commit 860fe8b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/to-short-string-representation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ module.exports = function (t, a) {
if (typeof Symbol === "function") a(t(Symbol()), "Symbol()");
a(t(Object.create(null)), "<non-stringifiable value>");
a(t(repeat.call("a", 300)), repeat.call("a", 99) + "…");
a(t("mar\ntoo\nfar"), "mar too far");
a(t("mar\ntoo\nfar"), "mar\\ntoo\\nfar");
};
4 changes: 3 additions & 1 deletion to-short-string-representation.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module.exports = function (value) {
// Trim if too long
if (string.length > 100) string = string.slice(0, 99) + "…";
// Replace eventual new lines
string = string.replace(reNewLine, " ");
string = string.replace(reNewLine, function (char) {
return JSON.stringify(char).slice(1, -1);
});
return string;
};

0 comments on commit 860fe8b

Please sign in to comment.