to-short-string-representation.js 413 B

12345678910111213141516
  1. "use strict";
  2. var safeToString = require("./safe-to-string");
  3. var reNewLine = /[\n\r\u2028\u2029]/g;
  4. module.exports = function (value) {
  5. var string = safeToString(value);
  6. // Trim if too long
  7. if (string.length > 100) string = string.slice(0, 99) + "…";
  8. // Replace eventual new lines
  9. string = string.replace(reNewLine, function (char) {
  10. return JSON.stringify(char).slice(1, -1);
  11. });
  12. return string;
  13. };