Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

linkifyjs

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

linkifyjs - npm Package Compare versions

Comparing version 2.0.0-beta.2 to 2.0.0-beta.3

1

CHANGELOG.md

@@ -6,2 +6,3 @@ # Linkify Changelog

* New link-detection technique based on lexicographical analysis via two-stage scanner - essentially regexp with more flexibility.
* Faster, less destructive DOM manipulation.
* Node.js API via `var linkify = require('linkifyjs');`

@@ -8,0 +9,0 @@ * Internal plugin system so you can require only features you need. e.g., `require('linkifyjs/plugins/hashtag')(linkify);`

53

lib/linkify-element.js

@@ -15,2 +15,15 @@ /**

/**
Given a parent element and child node that the parent contains, replaces
that child with the given aary of new children
*/
function replaceChildWithChildren(parent, oldChild, newChildren) {
var lastNewChild = newChildren[newChildren.length - 1];
parent.replaceChild(lastNewChild, oldChild);
for (var i = newChildren.length - 2; i >= 0; i--) {
parent.insertBefore(newChildren[i], lastNewChild);
lastNewChild = newChildren[i];
}
}
/**
Given an array of MultiTokens, return an array of Nodes that are either

@@ -30,10 +43,10 @@ (a) Plain Text nodes (node type 3)

var tagName = _linkify.options.resolve(opts.tagName, token.type),
linkClass = _linkify.options.resolve(opts.linkClass, token.type),
target = _linkify.options.resolve(opts.target, token.type),
var href = token.toHref(opts.defaultProtocol),
formatted = _linkify.options.resolve(opts.format, token.toString(), token.type),
href = token.toHref(opts.defaultProtocol),
formattedHref = _linkify.options.resolve(opts.formatHref, href, token.type),
attributesHash = _linkify.options.resolve(opts.attributes, token.type),
events = _linkify.options.resolve(opts.events, token.type);
attributesHash = _linkify.options.resolve(opts.attributes, href, token.type),
tagName = _linkify.options.resolve(opts.tagName, href, token.type),
linkClass = _linkify.options.resolve(opts.linkClass, href, token.type),
target = _linkify.options.resolve(opts.target, href, token.type),
events = _linkify.options.resolve(opts.events, href, token.type);

@@ -56,7 +69,7 @@ // Build the link

if (events) {
for (var _event in events) {
for (var event in events) {
if (link.addEventListener) {
link.addEventListener(_event, events[_event]);
link.addEventListener(event, events[event]);
} else if (link.attachEvent) {
link.attachEvent('on' + _event, events[_event]);
link.attachEvent('on' + event, events[event]);
}

@@ -87,3 +100,3 @@ }

// Is this element already a link?
if (element.tagName.toLowerCase() === 'a' /*|| element.hasClass('linkified')*/) {
if (element.tagName === 'A' /*|| element.hasClass('linkified')*/) {
// No need to linkify

@@ -105,5 +118,11 @@ return element;

var str = childElement.nodeValue,
tokens = (0, _linkify.tokenize)(str);
children.push.apply(children, tokensToNodes(tokens, opts, doc));
tokens = (0, _linkify.tokenize)(str),
nodes = tokensToNodes(tokens, opts, doc);
// Swap out the current child for the set of nodes
replaceChildWithChildren(element, childElement, nodes);
// so that the correct sibling is selected
childElement = nodes[nodes.length - 1];
break;

@@ -118,12 +137,2 @@

// Clear out the element
while (element.firstChild) {
element.removeChild(element.firstChild);
}
// Replace with all the new nodes
for (var i = 0; i < children.length; i++) {
element.appendChild(children[i]);
}
return element;

@@ -130,0 +139,0 @@ }

@@ -43,13 +43,13 @@ /**

var tagName = _linkify.options.resolve(opts.tagName, token.type),
linkClass = _linkify.options.resolve(opts.linkClass, token.type),
target = _linkify.options.resolve(opts.target, token.type),
var href = token.toHref(opts.defaultProtocol),
formatted = _linkify.options.resolve(opts.format, token.toString(), token.type),
href = token.toHref(opts.defaultProtocol),
formattedHref = _linkify.options.resolve(opts.formatHref, href, token.type),
attributesHash = _linkify.options.resolve(opts.attributes, token.type);
attributesHash = _linkify.options.resolve(opts.attributes, href, token.type),
tagName = _linkify.options.resolve(opts.tagName, href, token.type),
linkClass = _linkify.options.resolve(opts.linkClass, href, token.type),
target = _linkify.options.resolve(opts.target, href, token.type);
var link = '<' + tagName + ' href="' + cleanAttr(formattedHref) + '" class="' + linkClass + '"';
var link = '<' + tagName + ' href="' + cleanAttr(formattedHref) + '" class="' + cleanAttr(linkClass) + '"';
if (target) {
link += ' target="' + target + '"';
link += ' target="' + cleanAttr(target) + '"';
}

@@ -56,0 +56,0 @@

@@ -8,3 +8,3 @@ 'use strict';

function typeToTarget(type) {
function typeToTarget(href, type) {
return type === 'url' ? '_blank' : null;

@@ -11,0 +11,0 @@ }

{
"name": "linkifyjs",
"version": "2.0.0-beta.2",
"version": "2.0.0-beta.3",
"description": "Intelligent link recognition, made easy",

@@ -18,2 +18,14 @@ "repository": {

"license": "MIT",
"keywords": [
"jquery",
"link",
"autolink",
"text",
"url",
"email",
"hashtag",
"hashtags",
"mention",
"mentions"
],
"dependencies": {},

@@ -20,0 +32,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc