diff --git a/lib/serializer.js b/lib/serializer.js index 2291baa4..ea810293 100644 --- a/lib/serializer.js +++ b/lib/serializer.js @@ -98,23 +98,24 @@ module.exports = class Serializer { } asString (str) { - const quotes = '"' - if (str instanceof Date) { - return quotes + str.toISOString() + quotes - } else if (str === null) { - return '""' - } else if (str instanceof RegExp) { - str = str.source - } else if (typeof str !== 'string') { - str = str.toString() + if (typeof str !== 'string') { + if (str === null) { + return '""' + } + if (str instanceof Date) { + return '"' + str.toISOString() + '"' + } + if (str instanceof RegExp) { + str = str.source + } else { + str = str.toString() + } } // Fast escape chars check if (!STR_ESCAPE.test(str)) { - return quotes + str + quotes - } - - if (str.length < 42) { + return '"' + str + '"' + } else if (str.length < 42) { return this.asStringSmall(str) } else { return JSON.stringify(str)