src/node.js
/**
 * @credits pino/lib/tools.js
 * magically escape strings for json
 * relying on their charCodeAt
 * everything below 32 needs JSON.stringify()
 * 34 and 92 happens all the time, so we
 * have a fast case for them
 */
@credits pino/lib/tools.js
magically escape strings for json
relying on their charCodeAt
everything below 32 needs JSON.stringify()
34 and 92 happens all the time, so we
have a fast case for them
@credits pino / lib / tools . js magically escape strings for json relying on their charCodeAt everything below 32 needs JSON . stringify () 34 and 92 happens all the time so we have a fast case for them
function asString (str) {
  let result = ''
  let last = 0
  let found = false
  let point = 255
  const l = str.length
  if (l > 100) {
    return JSON.stringify(str)
  }
  for (let i = 0; i < l && point >= 32; i++) {
    point = str.charCodeAt(i)
    if (point === 34 || point === 92) {
      result += str.slice(last, i) + '\\'
      last = i
      found = true
    }
  }
  if (!found) {
    result = str
  } else {
    result += str.slice(last)
  }
  return point < 32 ? JSON.stringify(str) : '"' + result + '"'
}
function asString ( str ) { let result = '' let last = 0 let found = false let point = 255 const l = str . length if ( l > 100 ) { return JSON . stringify ( str ) } for ( let i = 0 ; i < l && point >= 32 ; i ++ ) { point = str . charCodeAt ( i ) if ( point === 34 || point === 92 ) { result += str . slice ( last , i ) + '\\' last = i found = true } } if ( ! found ) { result = str } else { result += str . slice ( last ) } return point < 32 ? JSON . stringify ( str ) : '"' + result + '"' }
@credits pino/lib/tools.js
 magically escape strings for json
 relying on their charCodeAt
 everything below 32 needs JSON.stringify()
 34 and 92 happens all the time, so we
 have a fast case for them
@credits pino / lib / tools . js magically escape strings for json relying on their charCodeAt everything below 32 needs JSON . stringify () 34 and 92 happens all the time so we have a fast case for them