Linkify 2.1 released! ×

Jump to…

Installation

Node.js/Browserify

var linkify = require('linkifyjs');

AMD

<script src="linkify.amd.js"></script>
<script>
  require(['linkify'], function (linkify) {
    // …
  });
</script>

Browser globals

<script src="linkify.js"></script>

Methods

linkify.find (str [, type])

Finds all links in the given string

Params

  • String str Search string
  • String [type] only find links of the given type

Returns Array List of links where each element is a hash with properties type, value, and href:

  • type is the type of entity found. Possible values are
    • 'url'
    • 'email'
    • 'hashtag' (with Hashtag plugin)
    • 'mention' (with Mention plugin)
  • value is the original entity substring.
  • href should be the value of this link’s href attribute.
linkify.find('For help with GitHub.com, please email support@github.com');

Returns the array

[
  {
    type: 'url',
    value: 'GitHub.com',
    href: 'http://github.com',
  },
  {
    type: 'email',
    value: 'support@github.com',
    href: 'mailto:support@github.com'
  }
]

linkify.test (str [, type])

Is the given string a link? Not to be used for strict validation - See Caveats

Params

  • String str Test string
  • String [type] returns true only if the link is of the given type (see linkify.find),

Returns Boolean

linkify.test('google.com'); // true
linkify.test('google.com', 'email'); // false

linkify.tokenize (str)

Internal method used to perform lexicographical analysis on the given string and output the resulting token array.

Params

  • String str

Returns Array