npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aiserg-auto-link

v1.0.2

Published

Replace URLs and emails in text with HTML links, ignore the URLs within a href/pre tag.

Downloads

1

Readme

Auto-link

Auto-link is an npm package that replaces URLs and emails in text with HTML links, ignore the URLs within a href/pre tag.

Installation

npm install --save auto-link

Usage

var autoLink = require('auto-link');

Using the link() method:

var html = autoLink.link(text[, options]);

Example

var html = autoLink.link('<p>Welcom to www.google.com</p>');
//<p>Welcom to <a href="http://www.google.com">www.google.com</a></p>

Options

These are specified by providing an Object as the second parameter to autoLink.link().

  • target: String or Boolean
    A target attribute will be added to the replaced href tag if the target option is a String value. false means that do not add target attribuite.
    Default value is false.
    e.g.
autoLink.link('<p>Welcom to www.google.com</p>', {
    target: '_blank'
});
//<p>Welcom to <a href="http://www.google.com" target="_blank">www.google.com</a></p>
  • attrs: Object
    The attributes you want to add to the replaced href tag. e.g.
autoLink.link('<p>Welcom to www.google.com</p>', {
    attrs: {
        class: 'mylink',
        name: 'mylink1',
        id: 'mylink2'
    }
});
//<p>Welcom to <a href="http://www.google.com" class="mylink" name="mylink1" id="mylink2">www.google.com</a></p>
  • ignore.tags: Array[String]
    The URLs text within some tags should not be replaces. for example: <a href="http://www.google.com">www.google.com</a> should NOT be replaced to <a href="<a href="http://www.google.com">http://www.google.com</a>"><a href="http://www.google.com">www.google.com</a></a>. So the The URLs text within ignore.tags won't be replaced.
    Defaults value is ['a', 'pre', 'code', 'textarea'].
    e.g.
autoLink.link('<p>Welcom to <a href="http://www.google.com">www.google.com</a></p>');
//<p>Welcom to <a href="http://www.google.com">www.google.com</a></p>

autoLink.link('<p>Welcom to www.google.com</p>, <span>www.stackoverflow.com</span> and <pre>www.github.com</pre>', {
        ignore: {
            tags: ['p', 'span']
        }
    });
//<p>Welcom to www.google.com</p>, <span>www.stackoverflow.com</span> and <pre><a href="http://www.github.com">www.github.com</a></pre>
  • ignore.classes: Array[String]
    The same with ignore.tags, but it's for CSS classes.
    Defaults values is ['hljs'].

e.g.

autoLink.link('<p class="hljs">Welcom to www.google.com <span class="myclass">and www.github.com</span></p>', {
        ignore: {
            classes: ['myclass']
        }
    });
//<p class="hljs">Welcom to <a href="http://www.google.com">www.google.com</a> <span class="myclass">and www.github.com</span></p>
  • ignore.fn: Function
    Sometimes it's hard to filter the elements by tags and CSS classes. so the ignore.fn is used to filter the elements which you want to ignore. The function has a JSDOM element as it's parameter, it should retrun a boolean value to specify the element ignores or not.
    If enable the ignore.fn option, the ignore.tags and ignore.classes options will be invalidated.
    e.g.
autoLink.link('<p id="hljs">Welcom to www.google.com <span id="myid1">and www.github.com</span></p>', {
        ignore: {
            fn: function(ele) {
                return ele.attr('id') && ele.attr('id').indexOf('myid') > -1;
            }
        }
    });
//<p id="hljs">Welcom to <a href="http://www.google.com">www.google.com</a> <span id="myid1">and www.github.com</span></p>

Tests

$ npm install -g mocha
npm test