How to use the urijs.withinString function in urijs

To help you get started, weā€™ve selected a few urijs 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 d3estudio / d3-digest / src / processor / proc.js View on Github external
});
            break;

        case 'message_deleted':
            this.collection.deleteMany({ ts: msg.deleted_ts }, (err, res) => {
                if(res) {
                    logger.verbose('Proc', `Message TS ${msg.deleted_ts} removed. Affected row(s): `, res.deletedCount);
                }
                callback();
            });
            break;

        case 'message_changed':
            logger.verbose('Proc', `Message TS ${msg.message.ts} was edited.`);
            matches = [];
            URI.withinString(msg.message.text, (u) => {
                matches.push(u);
                return u;
            });
            if(matches && matches.length > 0) {
                logger.verbose('Proc', `Message TS ${msg.message.ts} still is eligible.`);
                // Insert or update.
                this.collection.findOne({ ts: msg.message.ts })
                    .then((doc) => {
                        if(doc) {
                            // update.
                            if(doc.text !== msg.message.text) {
                                logger.verbose('Proc', `Message TS ${msg.message.ts} found on storage. Updating text...`);
                                doc.text = msg.message.text;
                                doc.ready = false;
                                this.collection.replaceOne({ ts: msg.message.ts }, doc, () => {
                                    this.requestPurge(doc);
github arj03 / ssb-dat-autoshare / lib.js View on Github external
logs.forEach(msg => {
      uri.withinString(msg.value.content.text, (datLink) => {
        if (!datLink.startsWith("dat://")) return

        // issue #360 in uri.js
        var bracket = datLink.indexOf("]")

        if (bracket != -1)
          datLink = datLink.substring(0, bracket)

        var hash = datLink.indexOf("#")

        if (hash != -1)
          datLink = datLink.substring(0, hash)

	var sharePath = shareFolder + "/" + datLink.substring(6)

	if (!sharePath.endsWith("/"))
github funsocietyirc / MrNodeBot / lib / extractUrls.js View on Github external
module.exports = (text, limit = 0) => {
    const urls = [];
    uri.withinString(text, (rawUrl) => {
        // Grab a url from upstream
        const url = uri(rawUrl).toString();
        // Exclusions
        if (
            // Remove empty matches, http(s)://(/) or www(.)
            !url.match(/^(?:http[s]?:\/{1,3}|www[.]?)$/im)
        )
        // Push result
        { urls.push(url); }
    });

    return (Number.isInteger(limit) && limit > 0) ? _.take(urls, limit) : urls;
};
github d3estudio / d3-digest / src / prefetch / cachemanager.js View on Github external
run(doc) {
        var url = null;
        URI.withinString(doc.text, (u) => {
            url = url || u;
            return u;
        });
        if(!url) {
            return Promise.reject(new Error('Document does not has a valid url'));
        } else {
            doc.url = url;
            return this.runPlugins(doc);
        }
    }
github molgenis / molgenis / molgenis-core-ui / src / main / javascript / modules / react-components / FormControl.js View on Github external
render: function () {
        var text = this.props.description;

        var keyIdx = 0;
        var idx = 0;
        var DescriptionParts = [];
        URI.withinString(text, function (url, start, end) {
            if (start > idx) {
                DescriptionParts.push(span({key: '' + keyIdx++}, text.substr(idx, start)));
            }
            DescriptionParts.push(a({href: url, target: '_blank', key: '' + keyIdx++}, url));

            idx = end;
            return url;
        });
        if (idx < text.length) {
            DescriptionParts.push(span({key: '' + keyIdx++}, text.substr(idx)));
        }
        return span({className: 'help-block'}, DescriptionParts);
    }
});
github MixinNetwork / desktop-app / src / utils / content_util.js View on Github external
renderUrl(content) {
    const h = content
      .replace(/&/g, '&')
      .replace(//g, '>')
      .replace(/"/g, '"')
    const result = URI.withinString(h, function(url) {
      let l = url
      if (!url.startsWith('http')) {
        l = 'https://' + url
      }
      return `<a rel="noopener noreferrer nofollow" href="${l}">${url}</a>`
    })
    return result
  }
}
github conversejs / converse.js / src / utils / html.js View on Github external
u.addHyperlinks = function (text) {
    return URI.withinString(text, url =&gt; {
        const uri = new URI(url);
        url = uri.normalize()._string;
        const pretty_url = uri._parts.urn ? url : uri.readable();
        if (!uri._parts.protocol &amp;&amp; !url.startsWith('http://') &amp;&amp; !url.startsWith('https://')) {
            url = 'http://' + url;
        }
        if (uri._parts.protocol === 'xmpp' &amp;&amp; uri._parts.query === 'join') {
            return `<a href="${url}" class="open-chatroom" rel="noopener">${u.escapeHTML(pretty_url)}</a>`;
        }
        return `<a href="${url}" rel="noopener">${u.escapeHTML(pretty_url)}</a>`;
    }, {
        'start': /\b(?:([a-z][a-z0-9.+-]*:\/\/)|xmpp:|mailto:|www\.)/gi
    });
};
github molgenis / molgenis / molgenis-core-ui / src / main / frontend / src / modules / react-components / FormControl.js View on Github external
render: function () {
        var text = this.props.description;

        var keyIdx = 0;
        var idx = 0;
        var DescriptionParts = [];
        URI.withinString(text, function (url, start, end) {
            if (start &gt; idx) {
                DescriptionParts.push(span({key: '' + keyIdx++}, text.substr(idx, start)));
            }
            DescriptionParts.push(a({href: url, target: '_blank', key: '' + keyIdx++}, url));

            idx = end;
            return url;
        });
        if (idx &lt; text.length) {
            DescriptionParts.push(span({key: '' + keyIdx++}, text.substr(idx)));
        }
        return span({className: 'help-block'}, DescriptionParts);
    }
});