linkify-it vs linkifyjs vs autolinker vs url-regex-safe vs linkify-html vs linkify-string
JavaScript Link Parsing Libraries Comparison
1 Year
linkify-itlinkifyjsautolinkerurl-regex-safelinkify-htmllinkify-stringSimilar Packages:
What's JavaScript Link Parsing Libraries?

These libraries are designed to automatically detect and convert plain text URLs, email addresses, and hashtags into clickable links in web applications. They help enhance user experience by making it easier for users to interact with content that contains links, improving accessibility and usability. Each library offers unique features and capabilities, catering to different needs in link parsing and formatting.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
linkify-it8,931,42767855.4 kB11a year agoMIT
linkifyjs1,739,2801,928261 kB303 months agoMIT
autolinker956,3591,4842.12 MB622 months agoMIT
url-regex-safe148,5538174.9 kB42 years agoMIT
linkify-html105,1711,928130 kB303 months agoMIT
linkify-string50,3021,9289.72 kB303 months agoMIT
Feature Comparison: linkify-it vs linkifyjs vs autolinker vs url-regex-safe vs linkify-html vs linkify-string

Link Detection

  • linkify-it:

    Linkify-it offers a highly customizable link detection system that allows developers to define their own rules for recognizing links, making it suitable for complex applications with unique link formats.

  • linkifyjs:

    Linkifyjs supports a wide range of link types, including URLs, email addresses, and custom link patterns, making it a versatile choice for applications that need comprehensive link detection capabilities.

  • autolinker:

    Autolinker provides a simple yet effective mechanism for detecting URLs, email addresses, and hashtags in plain text, making it easy to convert them into clickable links without additional configuration.

  • url-regex-safe:

    url-regex-safe provides a secure way to detect URLs using safe regex patterns, ensuring that the detection process is efficient and does not expose the application to regex-related vulnerabilities.

  • linkify-html:

    Linkify-html excels at detecting links within HTML content, ensuring that links are properly formatted while preserving the surrounding HTML structure, which is crucial for rich text applications.

  • linkify-string:

    Linkify-string focuses on detecting links in plain text strings efficiently, providing a lightweight solution for applications that require fast link detection without the overhead of additional features.

Customization

  • linkify-it:

    Linkify-it is highly customizable, allowing developers to define their own link detection rules and customize the output format, making it suitable for applications with specific requirements.

  • linkifyjs:

    Linkifyjs offers extensive customization capabilities, allowing developers to modify link detection rules, styles, and behaviors, making it suitable for complex applications that require flexibility.

  • autolinker:

    Autolinker offers limited customization options, focusing on simplicity and ease of use, making it ideal for straightforward applications that do not require extensive configuration.

  • url-regex-safe:

    url-regex-safe is primarily focused on security and does not offer extensive customization options, making it suitable for applications that prioritize safe URL detection.

  • linkify-html:

    Linkify-html allows for some customization in how links are rendered, enabling developers to specify link attributes and styles, which is beneficial for maintaining consistent UI design.

  • linkify-string:

    Linkify-string provides minimal customization options, focusing on performance and simplicity, which is ideal for applications that prioritize speed over extensive configuration.

Performance

  • linkify-it:

    Linkify-it is optimized for performance and can handle large volumes of text efficiently, making it suitable for applications that require high-performance link detection.

  • linkifyjs:

    Linkifyjs is designed to handle a wide range of link types efficiently, providing good performance even in complex scenarios with many links to process.

  • autolinker:

    Autolinker is designed for performance, providing fast link detection and conversion suitable for applications with moderate link processing needs without significant overhead.

  • url-regex-safe:

    url-regex-safe is optimized for performance while ensuring safe regex patterns are used, making it suitable for applications that require both speed and security.

  • linkify-html:

    Linkify-html may introduce some performance overhead due to its handling of HTML content, but it is optimized for typical use cases involving rich text.

  • linkify-string:

    Linkify-string is lightweight and fast, making it an excellent choice for applications that need quick link detection in plain text without additional processing overhead.

Ease of Use

  • linkify-it:

    Linkify-it has a moderate learning curve due to its customization options, but once understood, it provides powerful capabilities for link detection.

  • linkifyjs:

    Linkifyjs may require more initial setup due to its extensive features, but it offers comprehensive documentation to help developers get started quickly.

  • autolinker:

    Autolinker is very easy to use, requiring minimal setup and configuration, making it ideal for developers looking for a quick solution to link detection.

  • url-regex-safe:

    url-regex-safe is easy to use for developers familiar with regex, providing a simple API for safe URL detection.

  • linkify-html:

    Linkify-html is user-friendly for developers familiar with HTML, allowing them to easily integrate link detection into their applications without steep learning curves.

  • linkify-string:

    Linkify-string is straightforward and easy to implement, making it a great choice for developers who need a simple solution for link detection in strings.

Security

  • linkify-it:

    Linkify-it does not have built-in security features but allows developers to implement their own security measures during link detection and formatting.

  • linkifyjs:

    Linkifyjs is designed with security in mind, providing robust link detection capabilities while minimizing the risk of vulnerabilities in link processing.

  • autolinker:

    Autolinker does not focus heavily on security features but provides basic link detection without exposing vulnerabilities, suitable for general use cases.

  • url-regex-safe:

    url-regex-safe is specifically designed to prevent regex-related vulnerabilities, ensuring that URL detection is both efficient and secure.

  • linkify-html:

    Linkify-html is secure for handling HTML content, ensuring that links are processed safely without introducing XSS vulnerabilities.

  • linkify-string:

    Linkify-string is secure for plain text processing, ensuring that link detection does not expose the application to vulnerabilities.

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

    Select Linkify-it for a more customizable and extensible solution that allows for advanced link detection and formatting. It's suitable for applications that need fine-tuned control over how links are processed and displayed.

  • linkifyjs:

    Choose Linkifyjs if you need a robust library that supports a wide range of link types and offers extensive customization options. It's great for applications that require flexibility and advanced features in link parsing.

  • autolinker:

    Choose Autolinker if you need a straightforward solution for converting URLs, email addresses, and hashtags into links with minimal configuration. It is particularly useful for simple applications where ease of use is a priority.

  • url-regex-safe:

    Opt for url-regex-safe if you need a reliable way to validate and extract URLs from strings safely, ensuring that the regex patterns used are secure and won't lead to issues such as ReDoS (Regular Expression Denial of Service). This is essential for applications that prioritize security.

  • linkify-html:

    Opt for Linkify-html if you require a library that can handle HTML content and convert links while preserving the original HTML structure. This is ideal for applications that deal with rich text or user-generated content.

  • linkify-string:

    Use Linkify-string if you want a lightweight library focused on converting plain strings into links without additional dependencies. This is perfect for simple use cases where performance is critical.

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