packages/insomnia-prettify/src/json.js
function _convertUnicode(originalStr) {
  let m;
  let c;
  let cStr;
  let lastI = 0;

  // Matches \u#### but not \\u####
  const unicodeRegex = /\\u[0-9a-fA-F]{4}/g;

  let convertedStr = '';
  while ((m = unicodeRegex.exec(originalStr))) {
    // Don't convert if the backslash itself is escaped
    if (originalStr[m.index - 1] === '\\') {
      continue;
    }

    try {
      cStr = m[0].slice(2); // Trim off start
      c = String.fromCharCode(parseInt(cStr, 16));
      if (c === '"') {
        // Escape it if it's double quotes
        c = `\\${c}`;
      }

      // + 1 to account for first matched (non-backslash) character
      convertedStr += originalStr.slice(lastI, m.index) + c;
      lastI = m.index + m[0].length;
    } catch (err) {
      // Some reason we couldn't convert a char. Should never actually happen
      console.warn('Failed to convert unicode char', m[0], err);
    }
  }

  // Finally, add the rest of the string to the end.
  convertedStr += originalStr.slice(lastI, originalStr.length);

  return convertedStr;
}
function _convertUnicode(originalStr) {
  let m;
  let c;
  let cStr;
  let lastI = 0;

  // Matches \u#### but not \\u####
  const unicodeRegex = /\\u[0-9a-fA-F]{4}/g;

  let convertedStr = '';
  while ((m = unicodeRegex.exec(originalStr))) {
    // Don't convert if the backslash itself is escaped
    if (originalStr[m.index - 1] === '\\') {
      continue;
    }

    try {
      cStr = m[0].slice(2); // Trim off start
      c = String.fromCharCode(parseInt(cStr, 16));
      if (c === '"') {
        // Escape it if it's double quotes
        c = `\\${c}`;
      }

      // + 1 to account for first matched (non-backslash) character
      convertedStr += originalStr.slice(lastI, m.index) + c;
      lastI = m.index + m[0].length;
    } catch (err) {
      // Some reason we couldn't convert a char. Should never actually happen
      console.warn('Failed to convert unicode char', m[0], err);
    }
  }

  // Finally, add the rest of the string to the end.
  convertedStr += originalStr.slice(lastI, originalStr.length);

  return convertedStr;
}
function _convertUnicode ( originalStr ) { let m ; let c ; let cStr ; let lastI = 0 ; // Matches \u#### but not \\u#### const unicodeRegex = / \\u[0-9a-fA-F]{4} / g ; let convertedStr = '' ; while ( ( m = unicodeRegex . exec ( originalStr ) ) ) { // Don't convert if the backslash itself is escaped if ( originalStr [ m . index - 1 ] === '\\' ) { continue ; } try { cStr = m [ 0 ] . slice ( 2 ) ; // Trim off start c = String . fromCharCode ( parseInt ( cStr , 16 ) ) ; if ( c === '"' ) { // Escape it if it's double quotes c = ` \\ ${ c } ` ; } // + 1 to account for first matched (non-backslash) character convertedStr += originalStr . slice ( lastI , m . index ) + c ; lastI = m . index + m [ 0 ] . length ; } catch ( err ) { // Some reason we couldn't convert a char. Should never actually happen console . warn ( 'Failed to convert unicode char' , m [ 0 ] , err ) ; } } // Finally, add the rest of the string to the end. convertedStr += originalStr . slice ( lastI , originalStr . length ) ; return convertedStr ; }
Convert escaped unicode characters to real characters. Any JSON parser will do this by
default. This is really fast too. Around 25ms for ~2MB of data with LOTS of unicode.

@param originalStr
@returns {string}
@private
Convert escaped unicode characters to real characters . Any JSON parser will do this by default . This is really fast too . Around 25ms for ~2MB of data with LOTS of unicode .