How to use the twitter-text.convertUnicodeIndices function in twitter-text

To help you get started, we’ve selected a few twitter-text 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 vanita5 / birdknife / src / libs / text.js View on Github external
static autoBoldText(text, entities) {
        if (!entities) return;
        twitter.convertUnicodeIndices(text, entities, false);

        let result = '';
        entities.sort((a, b) =>
            a.indices[0] - b.indices[0]
        );

        let beginIndex = 0;
        for (const entity of entities) {
            result += text.substring(beginIndex, entity.indices[0]);
            if (entity.type) { // Only 'photo' for now (https://dev.twitter.com/overview/api/entities-in-twitter-objects)
                result += Color.bold(entity.display_url);
            } else if (entity.expanded_url) { // url
                result += Color.bold(entity.expanded_url);
            } else if (entity.screen_name) { // reply
                result += Color.bold('@' + entity.screen_name);
            } else if (entity.text) { // hashtag
github vanita5 / birdknife / libs / birdknife-text.js View on Github external
autoBoldText: function(text, entities) {
        twitter.convertUnicodeIndices(text, entities, false);

        var result = "";
        entities.sort(function(a, b) {
            return a.indices[0] - b.indices[0];
        });

        var beginIndex = 0;
        for (var i = 0; i < entities.length; i++) {
            var entity = entities[i];
            result += text.substring(beginIndex, entity.indices[0]);

            if (entity.type) { //Only 'photo' for now (https://dev.twitter.com/overview/api/entities-in-twitter-objects)
                result += color.bold(entity.display_url);
            } else if (entity.expanded_url) { //url
                result += color.bold(entity.expanded_url);
            } else if (entity.screen_name) { //reply