Skip to content

Commit

Permalink
Add safe stringify
Browse files Browse the repository at this point in the history
  • Loading branch information
apehead committed Dec 9, 2018
1 parent d35416a commit 41d1882
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Expand Up @@ -5,6 +5,7 @@ const dateformat = require('dateformat')
// remove jsonParser once Node 6 is not supported anymore
const jsonParser = require('fast-json-parse')
const jmespath = require('jmespath')
const stringifySafe = require('fast-safe-stringify')

const CONSTANTS = require('./lib/constants')

Expand Down Expand Up @@ -224,7 +225,7 @@ module.exports = function prettyFactory (options) {

for (var i = 0; i < keys.length; i += 1) {
if (errorLikeObjectKeys.indexOf(keys[i]) !== -1 && value[keys[i]] !== undefined) {
const lines = JSON.stringify(value[keys[i]], null, 2)
const lines = stringifySafe(value[keys[i]], null, 2)
if (lines === undefined) continue
const arrayOfLines = (
IDENT + keys[i] + ': ' +
Expand Down Expand Up @@ -254,7 +255,7 @@ module.exports = function prettyFactory (options) {
}
} else if (filteredKeys.indexOf(keys[i]) < 0) {
if (value[keys[i]] !== undefined) {
const lines = JSON.stringify(value[keys[i]], null, 2)
const lines = stringifySafe(value[keys[i]], null, 2)
if (lines !== undefined) {
result += IDENT + keys[i] + ': ' + joinLinesWithIndentation(lines) + EOL
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -34,6 +34,7 @@
"chalk": "^2.3.2",
"dateformat": "^3.0.3",
"fast-json-parse": "^1.0.3",
"fast-safe-stringify": "^2.0.6",
"jmespath": "^0.15.0",
"pump": "^3.0.0",
"readable-stream": "^3.0.6",
Expand Down

0 comments on commit 41d1882

Please sign in to comment.