linkify-it vs linkifyjs vs autolinker vs url-regex-safe vs linkify-html vs linkify-string
URL and Text Linking Libraries
linkify-itlinkifyjsautolinkerurl-regex-safelinkify-htmllinkify-stringSimilar Packages:
URL and Text Linking Libraries

URL and text linking libraries in JavaScript help developers automatically detect and convert URLs, email addresses, phone numbers, and other types of text into clickable links. These libraries are particularly useful for applications that handle user-generated content, such as social media platforms, chat applications, and content management systems. They provide a way to enhance the user experience by making text interactive without requiring manual HTML markup. These libraries offer various features, such as customization of link styles, support for different types of links, and handling of edge cases like nested links or special characters. They can be used in both client-side and server-side applications, making them versatile tools for web development.

Npm Package Weekly Downloads Trend
3 Years
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
linkify-it13,821,54171255.4 kB122 years agoMIT
linkifyjs3,983,9812,023260 kB386 months agoMIT
autolinker1,117,5251,4972.44 MB648 months agoMIT
url-regex-safe204,1198174.9 kB72 years agoMIT
linkify-html136,9292,023131 kB386 months agoMIT
linkify-string53,5882,0239.75 kB386 months agoMIT
Feature Comparison: linkify-it vs linkifyjs vs autolinker vs url-regex-safe vs linkify-html vs linkify-string

Linking Capabilities

  • linkify-it:

    linkify-it is designed for fast and accurate detection of URLs in plain text. It supports custom schemes and allows for the creation of custom linkification rules, providing flexibility for projects that need specialized URL detection.

  • linkifyjs:

    linkifyjs offers comprehensive linking capabilities for URLs, email addresses, and phone numbers. It is modular, allowing developers to include only the features they need, which helps optimize performance and bundle size.

  • autolinker:

    autolinker automatically detects and links URLs, email addresses, phone numbers, and social media handles (e.g., @username, #hashtag). It provides a comprehensive solution for linking various types of text, making it versatile for different applications.

  • url-regex-safe:

    url-regex-safe does not perform linking itself but provides a safe and reliable regular expression for detecting URLs in text. It is designed to minimize false positives and handle a wide range of URL formats, making it a valuable tool for applications that need accurate URL detection for further processing.

  • linkify-html:

    linkify-html focuses on converting plain text URLs into clickable links within HTML content. It preserves existing HTML markup while adding links, making it ideal for applications that need to process and sanitize user-generated HTML.

  • linkify-string:

    linkify-string provides a simple way to convert URLs in plain text strings into clickable links. It is lightweight and easy to use, making it suitable for projects that need a quick solution for linkifying text.

Customization

  • linkify-it:

    linkify-it is highly customizable, allowing developers to define their own linkification rules and schemes. This makes it ideal for projects that require specialized URL detection and linking behavior.

  • linkifyjs:

    linkifyjs provides a modular and customizable architecture, allowing developers to configure link styles, attributes, and behaviors. Its modularity makes it easy to extend and adapt to different use cases.

  • autolinker:

    autolinker allows for extensive customization of link styles, including the ability to set custom classes, attributes, and target behaviors. It also supports whitelisting and blacklisting of domains, making it easy to control which links are generated.

  • url-regex-safe:

    url-regex-safe does not provide customization for linking, as it is solely focused on URL detection. However, its reliable regex can be integrated into other tools and libraries that handle linking, allowing for accurate and customizable linkification.

  • linkify-html:

    linkify-html provides options for customizing the appearance and behavior of links, including setting classes, styles, and target attributes. It also allows for the use of custom linkifiers, enabling developers to define how links are created and rendered.

  • linkify-string:

    linkify-string offers basic customization options for link attributes, such as setting the target and rel attributes. It is designed to be simple and easy to use, with minimal configuration required.

Performance

  • linkify-it:

    linkify-it is designed for high performance and fast URL detection, making it ideal for applications that need to process large amounts of text quickly. Its lightweight nature ensures minimal impact on performance.

  • linkifyjs:

    linkifyjs is designed to be modular and efficient, allowing developers to include only the features they need. This helps optimize performance and reduce the impact on load times, especially in applications where only certain linking features are required.

  • autolinker:

    autolinker is optimized for performance, but its comprehensive feature set may introduce some overhead, especially when linking multiple types of content. It is suitable for most applications, but performance should be considered for very large texts or real-time processing.

  • url-regex-safe:

    url-regex-safe provides a highly efficient regular expression for URL detection, minimizing the performance impact during text processing. Its optimized regex makes it suitable for applications that need to detect URLs quickly and accurately.

  • linkify-html:

    linkify-html is efficient at processing HTML content and adding links, but performance can vary depending on the complexity of the HTML and the number of links being created. It is best suited for applications that process moderate amounts of HTML content.

  • linkify-string:

    linkify-string is a lightweight and fast library for converting URLs in plain text strings. Its simplicity ensures quick processing with minimal resource usage.

Ease of Use: Code Examples

  • linkify-it:

    linkify-it offers a simple API for URL detection, but its advanced features and customization options may require some time to fully understand and implement.

  • linkifyjs:

    linkifyjs provides a well-documented API with examples, making it easy to use while allowing for advanced customization. Its modular design allows developers to start with basic features and gradually incorporate more complex functionality as needed.

  • autolinker:

    autolinker provides a simple API for quick implementation, with clear documentation and examples. Its ease of use makes it accessible for developers of all skill levels.

  • url-regex-safe:

    url-regex-safe is straightforward to use for URL detection, with clear documentation on how to integrate the regex into other applications. It is a simple tool that can be easily incorporated into larger projects.

  • linkify-html:

    linkify-html is easy to use for converting URLs within HTML content, with straightforward API and good documentation. It is particularly useful for developers working with HTML and needing to add links dynamically.

  • linkify-string:

    linkify-string is very easy to use, with a simple API for converting URLs in plain text strings. It is ideal for quick implementations without the need for extensive configuration.

How to Choose: linkify-it vs linkifyjs vs autolinker vs url-regex-safe vs linkify-html vs linkify-string
  • linkify-it:

    Choose linkify-it if you need a fast and lightweight library for detecting URLs in plain text. It is highly configurable and allows for the creation of custom linkification rules, making it suitable for projects that require fine-tuned control over how links are detected and rendered.

  • linkifyjs:

    Choose linkifyjs if you need a full-featured library that supports linking URLs, email addresses, and phone numbers. It provides a modular architecture, allowing you to include only the features you need, which helps keep the bundle size small.

  • autolinker:

    Choose autolinker if you need a comprehensive solution that automatically detects and links URLs, email addresses, phone numbers, and social media handles. It is highly customizable and easy to use, making it ideal for projects that require quick implementation with minimal configuration.

  • url-regex-safe:

    Choose url-regex-safe if you need a reliable and safe regular expression for detecting URLs in text. It is designed to minimize false positives and handle a wide range of URL formats, making it suitable for applications that require accurate URL detection for further processing.

  • linkify-html:

    Choose linkify-html if you need to convert plain text URLs into clickable links within HTML content. It is particularly useful for applications that need to process and sanitize user-generated HTML while preserving existing markup.

  • linkify-string:

    Choose linkify-string if you need a simple utility for converting URLs in plain text strings into clickable links. It is lightweight and easy to use, making it ideal for projects that need a quick solution without extensive configuration.

README for linkify-it

linkify-it

CI NPM version Coverage Status Gitter

Links recognition library with FULL unicode support. Focused on high quality link patterns detection in plain text.

Demo

Why it's awesome:

  • Full unicode support, with astral characters!
  • International domains support.
  • Allows rules extension & custom normalizers.

Install

npm install linkify-it --save

Browserification is also supported.

Usage examples

Example 1
import linkifyit from 'linkify-it';
const linkify = linkifyit();

// Reload full tlds list & add unofficial `.onion` domain.
linkify
  .tlds(require('tlds'))          // Reload with full tlds list
  .tlds('onion', true)            // Add unofficial `.onion` domain
  .add('git:', 'http:')           // Add `git:` protocol as "alias"
  .add('ftp:', null)              // Disable `ftp:` protocol
  .set({ fuzzyIP: true });        // Enable IPs in fuzzy links (without schema)

console.log(linkify.test('Site github.com!'));  // true

console.log(linkify.match('Site github.com!')); // [ {
                                                //   schema: "",
                                                //   index: 5,
                                                //   lastIndex: 15,
                                                //   raw: "github.com",
                                                //   text: "github.com",
                                                //   url: "http://github.com",
                                                // } ]
Example 2. Add twitter mentions handler
linkify.add('@', {
  validate: function (text, pos, self) {
    const tail = text.slice(pos);

    if (!self.re.twitter) {
      self.re.twitter =  new RegExp(
        '^([a-zA-Z0-9_]){1,15}(?!_)(?=$|' + self.re.src_ZPCc + ')'
      );
    }
    if (self.re.twitter.test(tail)) {
      // Linkifier allows punctuation chars before prefix,
      // but we additionally disable `@` ("@@mention" is invalid)
      if (pos >= 2 && tail[pos - 2] === '@') {
        return false;
      }
      return tail.match(self.re.twitter)[0].length;
    }
    return 0;
  },
  normalize: function (match) {
    match.url = 'https://twitter.com/' + match.url.replace(/^@/, '');
  }
});

API

API documentation

new LinkifyIt(schemas, options)

Creates new linkifier instance with optional additional schemas. Can be called without new keyword for convenience.

By default understands:

  • http(s)://... , ftp://..., mailto:... & //... links
  • "fuzzy" links and emails (google.com, foo@bar.com).

schemas is an object, where each key/value describes protocol/rule:

  • key - link prefix (usually, protocol name with : at the end, skype: for example). linkify-it makes sure that prefix is not preceded with alphanumeric char.
  • value - rule to check tail after link prefix
    • String - just alias to existing rule
    • Object
      • validate - either a RegExp (start with ^, and don't include the link prefix itself), or a validator function which, given arguments text, pos, and self, returns the length of a match in text starting at index pos. pos is the index right after the link prefix. self can be used to access the linkify object to cache data.
      • normalize - optional function to normalize text & url of matched result (for example, for twitter mentions).

options:

  • fuzzyLink - recognize URL-s without http(s):// head. Default true.
  • fuzzyIP - allow IPs in fuzzy links above. Can conflict with some texts like version numbers. Default false.
  • fuzzyEmail - recognize emails without mailto: prefix. Default true.
  • --- - set true to terminate link with --- (if it's considered as long dash).

.test(text)

Searches linkifiable pattern and returns true on success or false on fail.

.pretest(text)

Quick check if link MAY BE can exist. Can be used to optimize more expensive .test() calls. Return false if link can not be found, true - if .test() call needed to know exactly.

.testSchemaAt(text, name, offset)

Similar to .test() but checks only specific protocol tail exactly at given position. Returns length of found pattern (0 on fail).

.match(text)

Returns Array of found link matches or null if nothing found.

Each match has:

  • schema - link schema, can be empty for fuzzy links, or // for protocol-neutral links.
  • index - offset of matched text
  • lastIndex - index of next char after mathch end
  • raw - matched text
  • text - normalized text
  • url - link, generated from matched text

.matchAtStart(text)

Checks if a match exists at the start of the string. Returns Match (see docs for match(text)) or null if no URL is at the start. Doesn't work with fuzzy links.

.tlds(list[, keepOld])

Load (or merge) new tlds list. Those are needed for fuzzy links (without schema) to avoid false positives. By default:

  • 2-letter root zones are ok.
  • biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф are ok.
  • encoded (xn--...) root zones are ok.

If that's not enough, you can reload defaults with more detailed zones list.

.add(key, value)

Add a new schema to the schemas object. As described in the constructor definition, key is a link prefix (skype:, for example), and value is a String to alias to another schema, or an Object with validate and optionally normalize definitions. To disable an existing rule, use .add(key, null).

.set(options)

Override default options. Missed properties will not be changed.

License

MIT