Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
exports.handleSurrogatePairs = function(message, emotes) {
// Entire message decoded to array of char codes, combines
// surrogate pairs to a single index
var decoded = punycode.ucs2.decode(message);
var surrogates = {};
var i;
for (i = 0; i < decoded.length; i++) {
// Not surrogate
if (decoded[i] <= 0xFFFF) continue;
surrogates[i] = true;
}
// We can loop through all emote ids and all indexes that id
// appears in the message, offsetting the indexes +1 for each
// surrogate pair occurring before the index
for (var id in emotes) {
if (!Object.hasOwnProperty.call(emotes, id)) continue;
ScreenBuffer.prototype.put = function put( x , y , attr , str )
{
var i , offset ;
var characters = punycode.ucs2.decode( str ) ;
var len = characters.length ;
if ( typeof x !== 'number' || x < 0 ) { x = 0 ; }
else if ( x >= this.width ) { x = this.width - 1 ; }
else { x = Math.floor( x ) ; }
if ( typeof y !== 'number' || y < 0 ) { y = 0 ; }
else if ( y >= this.height ) { y = this.height - 1 ; }
else { y = Math.floor( y ) ; }
if ( typeof attr !== 'number' ) { attr = 0 ; }
this.lineBuffer[ y ] = undefined ; // this line should be invalidated in the lineBuffer
for ( i = 0 ; i < len ; i ++ )
{
if (typeof str !== 'string') {
throw new TypeError('Expected a String');
}
if (!opts) opts = {};
var numeric = true;
if (opts.named) numeric = false;
if (opts.numeric !== undefined) numeric = opts.numeric;
var special = opts.special || {
'"': true, "'": true,
'<': true, '>': true,
'&': true
};
var codePoints = punycode.ucs2.decode(str);
var chars = [];
for (var i = 0; i < codePoints.length; i++) {
var cc = codePoints[i];
var c = punycode.ucs2.encode([ cc ]);
var e = revEntities[cc];
if (e && (cc >= 127 || special[c]) && !numeric) {
chars.push('&' + (/;$/.test(e) ? e : e + ';'));
}
else if (cc < 32 || cc >= 127 || special[c]) {
chars.push('&#' + cc + ';');
}
else {
chars.push(c);
}
}
return chars.join('');
if (typeof str !== 'string') {
throw new TypeError('Expected a String');
}
if (!opts) opts = {};
var numeric = true;
if (opts.named) numeric = false;
if (opts.numeric !== undefined) numeric = opts.numeric;
var special = opts.special || {
'"': true, "'": true,
'<': true, '>': true,
'&': true
};
var codePoints = punycode.ucs2.decode(str);
var chars = [];
for (var i = 0; i < codePoints.length; i++) {
var cc = codePoints[i];
var c = punycode.ucs2.encode([ cc ]);
var e = revEntities[cc];
if (e && (cc >= 127 || special[c]) && !numeric) {
chars.push('&' + (/;$/.test(e) ? e : e + ';'));
}
else if (cc < 32 || cc >= 127 || special[c]) {
chars.push('&#' + cc + ';');
}
else {
chars.push(c);
}
}
return chars.join('');
var numeric = true;
if (opts.named) numeric = false;
if (opts.numeric !== undefined) numeric = opts.numeric;
var special = opts.special || {
'"': true, "'": true,
'<': true, '>': true,
'&': true
};
var codePoints = punycode.ucs2.decode(str);
var chars = [];
for (var i = 0; i < codePoints.length; i++) {
var cc = codePoints[i];
var c = punycode.ucs2.encode([ cc ]);
var e = revEntities[cc];
if (e && (cc >= 127 || special[c]) && !numeric) {
chars.push('&' + (/;$/.test(e) ? e : e + ';'));
}
else if (cc < 32 || cc >= 127 || special[c]) {
chars.push('&#' + cc + ';');
}
else {
chars.push(c);
}
}
return chars.join('');
}
insert: function (text, pos) {
text = text || '';
if (pos === undefined) {
pos = this.buffer.length;
}
if (text.normalize) {
text = text.normalize('NFC');
}
var args = punycode.ucs2.decode(text);
var textLen = args.length;
args.unshift(0);
args.unshift(pos);
this.buffer.splice.apply(this.buffer, args);
this.cursor = pos + textLen;
this.trigger('change:buffer');
},
erase: function (num, pos) {
const events: RTTAction[] = [];
if (matchedSize < oldLen) {
events.push({
length: oldLen - matchedSize,
position: oldLen - suffixSize,
type: 'erase'
});
}
if (matchedSize < newLen) {
const insertedText = newText.slice(prefixSize, prefixSize + newLen - matchedSize);
events.push({
position: prefixSize,
text: Punycode.ucs2.encode(insertedText),
type: 'insert'
});
}
return events;
}
function resolve(codepoints, paragraphLevel, automaticLevel = false) {
const encoding = punycode.ucs2.encode(codepoints);
const normalForm = encoding.normalize('NFC');
const decoding = punycode.ucs2.decode(normalForm);
const points = fromJS(decoding);
const bidiTypes = points.map(lookupBidiType);
return resolvedLevelsWithInvisibles(points, bidiTypes, paragraphLevel, automaticLevel).toJS();
}
function normalized(str) {
return '"' + punycode.ucs2.decode(str).map(function(cp) { return uchar(cp) }).join('') + '"';
}