function encodeXML(str) {
    let ret = "";
    let lastIdx = 0;
    let match;
    while ((match = xmlReplacer.exec(str)) !== null) {
        const i = match.index;
        const char = str.charCodeAt(i);
        const next = xmlCodeMap.get(char);
        if (next !== undefined) {
            ret += str.substring(lastIdx, i) + next;
            lastIdx = i + 1;
        }
        else {
            ret += `${str.substring(lastIdx, i)}&#x${getCodePoint(str, i).toString(16)};`;
            // Increase by 1 if we have a surrogate pair
            lastIdx = xmlReplacer.lastIndex += Number((char & 0xfc00) === 0xd800);
        }
    }
    return ret + str.substr(lastIdx);
}
/**
 * Encodes all non-ASCII characters, as well as characters not valid in XML
 * documents using XML entities.
 *
 * If a character has no equivalent entity, a
 * numeric hexadecimal reference (eg. `&#xfc;`) will be used.
 */
Encodes all non-ASCII characters, as well as characters not valid in XML
documents using XML entities.

If a character has no equivalent entity, a
numeric hexadecimal reference  will be used.
Encodes all non - ASCII characters as well as characters not valid in XML documents using XML entities . If a character has no equivalent entity a numeric hexadecimal reference will be used .
function encodeXML(str) {
    let ret = "";
    let lastIdx = 0;
    let match;
    while ((match = xmlReplacer.exec(str)) !== null) {
        const i = match.index;
        const char = str.charCodeAt(i);
        const next = xmlCodeMap.get(char);
        if (next !== undefined) {
            ret += str.substring(lastIdx, i) + next;
            lastIdx = i + 1;
        }
        else {
            ret += `${str.substring(lastIdx, i)}&#x${getCodePoint(str, i).toString(16)};`;
            lastIdx = xmlReplacer.lastIndex += Number((char & 0xfc00) === 0xd800);
        }
    }
    return ret + str.substr(lastIdx);
}
function encodeXML ( str ) { let ret = "" ; let lastIdx = 0 ; let match ; while ( ( match = xmlReplacer . exec ( str ) ) !== null ) { const i = match . index ; const char = str . charCodeAt ( i ) ; const next = xmlCodeMap . get ( char ) ; if ( next !== undefined ) { ret += str . substring ( lastIdx , i ) + next ; lastIdx = i + 1 ; } else { ret += ` ${ str . substring ( lastIdx , i ) } ${ getCodePoint ( str , i ) . toString ( 16 ) } ` ; lastIdx = xmlReplacer . lastIndex += Number ( ( char & 0xfc00 ) === 0xd800 ) ; } } return ret + str . substr ( lastIdx ) ; }
Encodes all non-ASCII characters, as well as characters not valid in XML
 documents using XML entities.
Encodes all non - ASCII characters as well as characters not valid in XML documents using XML entities .
// Increase by 1 if we have a surrogate pair