How to use the punycode.ucs2 function in punycode

To help you get started, we’ve selected a few punycode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github night / BetterTTV / src / js / chat / helpers.js View on Github external
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;
github cronvel / terminal-kit / lib / screenBuffer2.js View on Github external
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 ++ )
	{
github jamesshore / lets_code_javascript / node_modules / karma / static / context.js View on Github external
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('');
github fossasia / susper.com / node_modules / karma / static / context.js View on Github external
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('');
github fossasia / susper.com / node_modules / karma / static / context.js View on Github external
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('');
}
github otalk / rtt-buffer / lib / display-buffer.js View on Github external
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) {
github legastero / stanza / src / helpers / RTT.ts View on Github external
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;
}
github bbc / unicode-bidirectional / src / main.js View on Github external
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();
}
github retorquere / zotero-better-bibtex / webpack / dateparser.js View on Github external
function normalized(str) {
  return '"' + punycode.ucs2.decode(str).map(function(cp) { return uchar(cp) }).join('') + '"';
}

punycode

A robust Punycode converter that fully complies to RFC 3492 and RFC 5891, and works on nearly all JavaScript platforms.

MIT
Latest version published 1 year ago

Package Health Score

74 / 100
Full package analysis