Security News
vlt Debuts New JavaScript Package Manager and Serverless Registry at NodeConf EU
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
linkify-it
Advanced tools
The linkify-it package is a tool for finding links such as URLs and email addresses in plain text and converting them into clickable hyperlinks. It is highly customizable and allows developers to tweak the link recognition to suit their needs.
URL Recognition
This feature allows the detection of URLs within a text string and provides details about the recognized URLs, such as the index of the match within the string.
const linkify = require('linkify-it')();
console.log(linkify.match('Visit http://example.com for more information.'));
Email Recognition
With this feature, linkify-it can identify email addresses in text and treat them as mailto: links, which can be useful for creating clickable email links.
const linkify = require('linkify-it')();
linkify.add('mailto:', 'mailto:');
console.log(linkify.match('Contact us at: info@example.com'));
Custom Schema
This feature allows developers to add custom schemas and protocols to be recognized by linkify-it, enabling the detection of non-standard or less common link types.
const linkify = require('linkify-it')();
linkify.add('git:', 'http:');
console.log(linkify.match('Clone the repo at git://github.com/user/repo.git'));
TLD Customization
Linkify-it allows for the addition of custom top-level domains (TLDs) to its list, which can be useful for recognizing and linking to URLs with non-standard TLDs.
const linkify = require('linkify-it')();
linkify.tlds('my', true);
console.log(linkify.match('Check out this cool site: example.my'));
Autolinker is a similar package that automatically converts URLs, email addresses, and Twitter handles into clickable links. It is similar to linkify-it but also includes options to truncate the length of the displayed URLs and to strip prefixes (e.g., 'http://').
url-regex is a package that provides a regular expression for matching URLs. Unlike linkify-it, url-regex does not offer the same level of customization or the ability to add new schemas or TLDs, but it is useful for simple URL matching.
Anchorme is another package that converts URLs and email addresses to clickable links. It offers features like link validation and the ability to convert links within a specific part of the text. It is comparable to linkify-it but with a different API and additional options for link validation.
Links recognition library with FULL unicode support. Focused on high quality link patterns detection in plain text.
Why it's awesome:
npm install linkify-it --save
Browserification is also supported.
var linkify = require('linkify-it')();
// Reload full tlds list & add uniffocial `.onion` domain.
linkify
.tlds(require('tlds')) // Reload with full tlds list
.tlds('.onion', true); // Add uniffocial `.onion` domain
.linkify.add('git:', 'http:'); // Add `git:` ptotocol as "alias"
.linkify.add('ftp:', null); // Disable `ftp:` ptotocol
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",
// } ]
linkify.add('@', {
validate: function (text, pos, self) {
var tail = text.slice(pos);
if (!self.re.twitter) {
self.re.twitter = new RegExp(
'^([a-zA-Z0-9_]){1,15}(?!_)(?=$|' + self.re.src_ZPCcCf + ')'
);
}
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(/^@/, '');
}
});
Creates new linkifier instance with optional additional schemas.
Can be called without new
keyword for convenience.
By default understands:
http(s)://...
, ftp://...
, mailto:...
& //...
linksschemas
is an object, where each key/value describes protocol/rule:
:
at the end, skype:
for example). linkify-it
makes shure that prefix is not preceeded with
alphanumeric char.RegExp
.Searches linkifiable pattern and returns true
on success or false
on fail.
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.
Similar to .test()
but checks only specific protocol tail exactly at given
position. Returns length of found pattern (0 on fail).
Returns Array
of found link matches or null if nothing found.
Each match has:
//
for
protocol-neutral links.Load (or merge) new tlds list. Those are user for fuzzy links (without prefix) to avoid false positives. By default this algorythm used:
xn--...
) root zones are ok.If list is replaced, then exact match for 2-chars root zones will be checked.
Add new rule with schema
prefix. For definition details see constructor
description. To disable existing rule use .add(name, null)
FAQs
Links recognition library with FULL unicode support
The npm package linkify-it receives a total of 5,983,490 weekly downloads. As such, linkify-it popularity was classified as popular.
We found that linkify-it demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt introduced its new package manager and a serverless registry this week, innovating in a space where npm has stagnated.
Security News
Research
The Socket Research Team uncovered a malicious Python package typosquatting the popular 'fabric' SSH library, silently exfiltrating AWS credentials from unsuspecting developers.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.