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

These libraries are designed to automatically detect and convert URLs, email addresses, and other linkable content in text into clickable links. They provide various methods for parsing and transforming text, making it easier for developers to enhance user interactions by linking relevant content without manual effort. Each library has its unique features, performance characteristics, and use cases, catering to different needs in web development.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
linkify-it10,025,79368555.4 kB12a year agoMIT
linkifyjs1,984,5251,946261 kB304 months agoMIT
autolinker1,028,2241,4832.12 MB644 months agoMIT
url-regex344,577353-216 years agoMIT
linkify-html114,0781,946130 kB304 months agoMIT
linkify-string63,4941,9469.72 kB304 months agoMIT
Feature Comparison: linkify-it vs linkifyjs vs autolinker vs url-regex vs linkify-html vs linkify-string

Link Detection

  • linkify-it:

    Linkify-it offers advanced link detection with customizable rules for various link formats. It is highly efficient and can handle complex patterns, making it suitable for applications that require precise control over what constitutes a link.

  • linkifyjs:

    Linkifyjs combines link detection with the ability to manipulate both strings and DOM elements. It can detect links in text and automatically convert them into clickable elements in the DOM, providing a flexible solution for web applications.

  • autolinker:

    Autolinker excels in detecting URLs, email addresses, and hashtags within text. It uses a simple API to parse and convert these elements into clickable links, making it user-friendly for developers looking for quick implementations.

  • url-regex:

    url-regex is a specialized library for detecting URLs using regular expressions. It is lightweight and efficient, making it perfect for applications that need to identify URLs quickly without the need for additional processing.

  • linkify-html:

    Linkify-html provides robust link detection capabilities, specifically designed to work with HTML content. It can identify links in plain text and convert them into HTML anchor tags while preserving the surrounding formatting, ensuring a seamless user experience.

  • linkify-string:

    Linkify-string focuses on detecting links in plain text and converting them into a format suitable for further processing. It is lightweight and efficient, making it ideal for applications that need basic link detection without additional features.

Customization

  • linkify-it:

    Linkify-it is highly customizable, allowing developers to define their own rules for link detection and formatting. This flexibility makes it ideal for applications with specific linking requirements or non-standard link formats.

  • linkifyjs:

    Linkifyjs provides a range of customization options for both link detection and DOM manipulation. Developers can easily adjust the behavior of link creation and styling, making it a versatile choice for various applications.

  • autolinker:

    Autolinker allows for some customization through options such as link target and class names. However, it is primarily designed for straightforward linking and may not offer extensive customization for advanced use cases.

  • url-regex:

    url-regex is primarily focused on URL detection and does not offer customization options for link formatting. It is best used in scenarios where simple URL identification is required without additional features.

  • linkify-html:

    Linkify-html provides options for customizing the link generation process, including the ability to specify link attributes and classes. This makes it suitable for applications that require rich text formatting along with links.

  • linkify-string:

    Linkify-string offers minimal customization options, focusing on simplicity and speed. It is best suited for scenarios where basic link detection is needed without the complexity of extensive customization.

Performance

  • linkify-it:

    Linkify-it is designed for high performance and can efficiently process large texts with complex link patterns. Its optimization for various link formats makes it suitable for applications requiring fast and reliable link detection.

  • linkifyjs:

    Linkifyjs maintains good performance across different use cases, efficiently detecting links in both strings and DOM elements. Its versatility does not compromise speed, making it suitable for dynamic applications.

  • autolinker:

    Autolinker is optimized for performance in typical use cases, providing fast link detection and conversion. Its straightforward approach ensures that it can handle moderate text sizes efficiently without significant overhead.

  • url-regex:

    url-regex is extremely fast for URL detection due to its regex-based approach. It is ideal for applications that require rapid identification of URLs in large texts without additional processing.

  • linkify-html:

    Linkify-html performs well with moderate text sizes but may experience performance degradation with very large texts due to its HTML parsing capabilities. It balances performance with the need for rich text handling.

  • linkify-string:

    Linkify-string is lightweight and performs exceptionally well with large strings, making it ideal for applications that need quick link detection without the overhead of HTML processing.

Integration

  • linkify-it:

    Linkify-it can be integrated into various JavaScript environments and is particularly useful in applications that require custom link handling. Its flexibility allows for seamless integration into existing codebases.

  • linkifyjs:

    Linkifyjs offers robust integration capabilities, allowing developers to use it in both string manipulation and DOM contexts. This versatility makes it a strong candidate for applications with diverse linking needs.

  • autolinker:

    Autolinker integrates easily with various JavaScript frameworks and libraries, making it a convenient choice for developers looking to add link detection to their applications without significant overhead.

  • url-regex:

    url-regex can be easily integrated into any JavaScript project where URL detection is required. Its lightweight nature ensures that it does not add significant overhead to applications.

  • linkify-html:

    Linkify-html is designed for integration with HTML content, making it suitable for applications that need to convert user-generated content into clickable links while preserving formatting.

  • linkify-string:

    Linkify-string is straightforward to integrate into projects that need basic link detection. Its simplicity makes it a good choice for developers looking for a quick solution without complex setup.

Use Cases

  • linkify-it:

    Linkify-it is perfect for applications that require custom link handling, such as messaging apps or forums where users may input various types of links that need to be detected and formatted accurately.

  • linkifyjs:

    Linkifyjs is versatile enough for both web applications and server-side processing, making it a great choice for applications that need to handle links in multiple contexts, including text and HTML.

  • autolinker:

    Autolinker is ideal for applications that require quick and easy linking of URLs, email addresses, and hashtags, such as chat applications, comment sections, or social media platforms.

  • url-regex:

    url-regex is ideal for applications that need to identify URLs quickly, such as data validation scripts or preprocessing text for further analysis.

  • linkify-html:

    Linkify-html is best suited for content management systems and blogging platforms where user-generated content needs to be displayed with clickable links while maintaining formatting.

  • linkify-string:

    Linkify-string is suitable for lightweight applications or scripts that need to process plain text and convert it into a linkable format without additional HTML requirements.

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

    Select Linkify-it for a highly customizable and efficient solution that supports various link formats. It is suitable for applications that need precise control over the linking process and can handle complex link patterns.

  • linkifyjs:

    Choose Linkifyjs for a comprehensive solution that supports both string and DOM manipulation. It is beneficial for projects that require linking in both plain text and HTML contexts, providing flexibility in how links are handled.

  • autolinker:

    Choose Autolinker if you need a straightforward solution for automatically linking URLs, email addresses, and hashtags in text. It is easy to use and integrates well with various frameworks, making it ideal for quick implementations.

  • url-regex:

    Select url-regex if you need a simple and efficient way to detect URLs in strings. This library is focused on regex-based URL detection and is ideal for scenarios where you want to identify URLs without converting them into clickable links.

  • linkify-html:

    Opt for Linkify-html if you require a library that can convert plain text into HTML links while preserving the original formatting. This is particularly useful for applications that need to display rich text with links.

  • linkify-string:

    Use Linkify-string if you want a lightweight library that focuses on transforming strings into links without additional HTML formatting. It's perfect for scenarios where you need simple text manipulation without the overhead of HTML.

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