packages/shape-map/lib/ShapeMapJison.js
/**
   * unescape numerics and allowed single-character escapes.
   * throws: if there are any unallowed sequences
   */
unescape numerics and allowed single-character escapes.
throws: if there are any unallowed sequences
unescape numerics and allowed single - character escapes . throws : if there are any unallowed sequences
function unescapeText (string, replacements) {
    const regex = /\\u([a-fA-F0-9]{4})|\\U([a-fA-F0-9]{8})|\\(.)/g;
    try {
      string = string.replace(regex, function (sequence, unicode4, unicode8, escapedChar) {
        let charCode;
        if (unicode4) {
          charCode = parseInt(unicode4, 16);
          if (isNaN(charCode)) throw new Error(); 
          return String.fromCharCode(charCode);
        }
        else if (unicode8) {
          charCode = parseInt(unicode8, 16);
          if (isNaN(charCode)) throw new Error(); 
          if (charCode < 0xFFFF) return String.fromCharCode(charCode);
          return String.fromCharCode(0xD800 + ((charCode -= 0x10000) >> 10), 0xDC00 + (charCode & 0x3FF));
        }
        else {
          const replacement = replacements[escapedChar];
          if (!replacement) throw new Error("no replacement found for '" + escapedChar + "'");
          return replacement;
        }
      });
      return string;
    }
    catch (error) { console.warn(error); return ''; }
  }
function unescapeText ( string , replacements ) { const regex = / \\u([a-fA-F0-9]{4})|\\U([a-fA-F0-9]{8})|\\(.) / g ; try { string = string . replace ( regex , function ( sequence , unicode4 , unicode8 , escapedChar ) { let charCode ; if ( unicode4 ) { charCode = parseInt ( unicode4 , 16 ) ; if ( isNaN ( charCode ) ) throw new Error ( ) ; return String . fromCharCode ( charCode ) ; } else if ( unicode8 ) { charCode = parseInt ( unicode8 , 16 ) ; if ( isNaN ( charCode ) ) throw new Error ( ) ; if ( charCode < 0xFFFF ) return String . fromCharCode ( charCode ) ; return String . fromCharCode ( 0xD800 + ( ( charCode -= 0x10000 ) >> 10 ) , 0xDC00 + ( charCode & 0x3FF ) ) ; } else { const replacement = replacements [ escapedChar ] ; if ( ! replacement ) throw new Error ( "no replacement found for '" + escapedChar + "'" ) ; return replacement ; } } ) ; return string ; } catch ( error ) { console . warn ( error ) ; return '' ; } }
unescape numerics and allowed single-character escapes.
unescape numerics and allowed single - character escapes .
// can never happen (regex), but helps performance // can never happen (regex), but helps performance