This page is outdated
You are reading documentation for Linkify v2. Browse the latest v3+ documentation.
Jump To
Core Linkify
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 stringString
[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 stringString
[type
] returnstrue
only if the link is of the given type (seelinkify.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