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

interweave-autolink

Package Overview
Dependencies
Maintainers
1
Versions
41
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

interweave-autolink - npm Package Compare versions

Comparing version 4.0.1 to 4.1.0

lib/types.d.ts

6

CHANGELOG.md

@@ -0,1 +1,7 @@

## 4.1.0 - 2019-01-25
#### 🚀 Updates
- Migrated build to Rollup for a smaller filesize.
# 4.0.0 - 2019-10-29

@@ -2,0 +8,0 @@

351

esm/index.js

@@ -1,13 +0,338 @@

/**
* @copyright 2016-2019, Miles Johnson
* @license https://opensource.org/licenses/MIT
*/
import Email, { EmailProps } from './Email';
import EmailMatcher from './EmailMatcher';
import Hashtag, { HashtagProps } from './Hashtag';
import HashtagMatcher from './HashtagMatcher';
import IpMatcher from './IpMatcher';
import Link, { LinkProps } from './Link';
import Url, { UrlProps } from './Url';
import UrlMatcher, { UrlMatcherOptions } from './UrlMatcher';
export { Email, EmailProps, EmailMatcher, Hashtag, HashtagProps, HashtagMatcher, IpMatcher, Link, LinkProps, Url, UrlProps, UrlMatcher, UrlMatcherOptions };
import React from 'react';
import { Matcher } from 'interweave';
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
return target;
};
return _extends.apply(this, arguments);
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function Link(_ref) {
var children = _ref.children,
href = _ref.href,
onClick = _ref.onClick,
newWindow = _ref.newWindow;
return React.createElement("a", {
href: href,
target: newWindow ? '_blank' : undefined,
onClick: onClick,
rel: "noopener noreferrer"
}, children);
}
function Email(_ref) {
var children = _ref.children,
email = _ref.email,
emailParts = _ref.emailParts,
props = _objectWithoutPropertiesLoose(_ref, ["children", "email", "emailParts"]);
return React.createElement(Link, _extends({}, props, {
href: "mailto:" + email
}), children);
}
function combinePatterns(patterns, options) {
if (options === void 0) {
options = {};
}
var regex = patterns.map(function (pattern) {
return pattern.source;
}).join(options.join || '');
if (options.capture) {
regex = "(" + regex + ")";
} else if (options.nonCapture) {
regex = "(?:" + regex + ")";
}
if (options.match) {
regex += options.match;
}
return new RegExp(regex, options.flags || '');
}
var VALID_ALNUM_CHARS = /[a-z0-9]/;
var VALID_PATH_CHARS = /(?:[a-zA-Z\u0400-\u04FF0-9\-_~!$&'()[\]\\/*+,;=.%]*)/;
var URL_SCHEME = /(https?:\/\/)?/;
var URL_AUTH = combinePatterns([/[a-z\u0400-\u04FF0-9\-_~!$&'()*+,;=.:]+/, /@/], {
capture: true,
match: '?'
});
var URL_HOST = combinePatterns([/(?:(?:[a-z0-9](?:[-a-z0-9_]*[a-z0-9])?)\.)*/, /(?:(?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?)\.)/, /(?:[a-z](?:[-a-z0-9]*[a-z0-9])?)/], {
capture: true
});
var URL_PORT = /(?::(\d{1,5}))?/;
var URL_PATH = combinePatterns([/\//, combinePatterns([/[-+a-z0-9!*';:=,.$/%[\]_~@|&]*/, /[-+a-z0-9/]/], {
match: '*',
nonCapture: true
})], {
capture: true,
match: '?'
});
var URL_QUERY = combinePatterns([/\?/, combinePatterns([VALID_PATH_CHARS, /[a-z0-9_&=]/], {
match: '?',
nonCapture: true
})], {
capture: true,
match: '?'
});
var URL_FRAGMENT = combinePatterns([/#/, combinePatterns([VALID_PATH_CHARS, /[a-z0-9]/], {
match: '?',
nonCapture: true
})], {
capture: true,
match: '?'
});
var URL_PATTERN = combinePatterns([URL_SCHEME, URL_AUTH, URL_HOST, URL_PORT, URL_PATH, URL_QUERY, URL_FRAGMENT], {
flags: 'i'
});
var IP_V4_PART = /(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/;
var IP_V4 = combinePatterns([IP_V4_PART, IP_V4_PART, IP_V4_PART, IP_V4_PART], {
capture: true,
join: '\\.'
});
var IP_PATTERN = combinePatterns([URL_SCHEME, URL_AUTH, IP_V4, URL_PORT, URL_PATH, URL_QUERY, URL_FRAGMENT], {
flags: 'i'
});
var HASHTAG_PATTERN = combinePatterns([/#/, combinePatterns([VALID_ALNUM_CHARS, /[-a-z0-9_]*/, VALID_ALNUM_CHARS], {
capture: true
})], {
flags: 'i'
});
var EMAIL_USERNAME_PART = /[a-z0-9!#$%&?*+=_{|}~-]+/;
var EMAIL_USERNAME = combinePatterns([VALID_ALNUM_CHARS, EMAIL_USERNAME_PART, VALID_ALNUM_CHARS, combinePatterns([/\./, VALID_ALNUM_CHARS, EMAIL_USERNAME_PART, VALID_ALNUM_CHARS], {
match: '?',
nonCapture: true
})], {
capture: true
});
var EMAIL_PATTERN = combinePatterns([EMAIL_USERNAME, URL_HOST], {
flags: 'i',
join: '@'
});
var EMAIL_DISTINCT_PATTERN = new RegExp("^" + EMAIL_PATTERN.source + "$", EMAIL_PATTERN.flags);
var TOP_LEVEL_TLDS = ['com', 'org', 'net', 'int', 'edu', 'gov', 'mil', 'aero', 'asia', 'cat', 'coop', 'jobs', 'mobi', 'museum', 'post', 'tel', 'travel', 'xxx', 'arpa', 'test', 'ac', 'ad', 'ae', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'as', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb', 'bd', 'be', 'bf', 'bg', 'bh', 'bi', 'bj', 'bl', 'bm', 'bn', 'bo', 'bq', 'br', 'bs', 'bt', 'bv', 'bw', 'by', 'bz', 'ca', 'cc', 'cd', 'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'cr', 'cu', 'cv', 'cw', 'cx', 'cy', 'cz', 'de', 'dj', 'dk', 'dm', 'do', 'dz', 'ec', 'ee', 'eg', 'eh', 'er', 'es', 'et', 'eu', 'fi', 'fj', 'fk', 'fm', 'fo', 'fr', 'ga', 'gb', 'gd', 'ge', 'gf', 'gg', 'gh', 'gi', 'gl', 'gm', 'gn', 'gp', 'gq', 'gr', 'gs', 'gt', 'gu', 'gw', 'gy', 'hk', 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'im', 'in', 'io', 'iq', 'ir', 'is', 'it', 'je', 'jm', 'jo', 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kp', 'kr', 'kw', 'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'lr', 'ls', 'lt', 'lu', 'lv', 'ly', 'ma', 'mc', 'md', 'me', 'mf', 'mg', 'mh', 'mk', 'ml', 'mm', 'mn', 'mo', 'mp', 'mq', 'mr', 'ms', 'mt', 'mu', 'mv', 'mw', 'mx', 'my', 'mz', 'na', 'nc', 'ne', 'nf', 'ng', 'ni', 'nl', 'no', 'np', 'nr', 'nu', 'nz', 'om', 'pa', 'pe', 'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'ps', 'pt', 'pw', 'py', 'qa', 're', 'ro', 'rs', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd', 'se', 'sg', 'sh', 'si', 'sj', 'sk', 'sl', 'sm', 'sn', 'so', 'sr', 'st', 'su', 'sv', 'sx', 'sy', 'sz', 'tc', 'td', 'tf', 'tg', 'th', 'tj', 'tk', 'tl', 'tm', 'tn', 'to', 'tp', 'tr', 'tt', 'tv', 'tw', 'tz', 'ua', 'ug', 'uk', 'um', 'us', 'uy', 'uz', 'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', 'wf', 'ws', 'ye', 'yt', 'za', 'zm', 'zw'];
var EmailMatcher = function (_Matcher) {
_inheritsLoose(EmailMatcher, _Matcher);
function EmailMatcher() {
return _Matcher.apply(this, arguments) || this;
}
var _proto = EmailMatcher.prototype;
_proto.replaceWith = function replaceWith(children, props) {
return React.createElement(Email, props, children);
};
_proto.asTag = function asTag() {
return 'a';
};
_proto.match = function match(string) {
return this.doMatch(string, EMAIL_PATTERN, function (matches) {
return {
email: matches[0],
emailParts: {
host: matches[2],
username: matches[1]
}
};
});
};
return EmailMatcher;
}(Matcher);
function Hashtag(_ref) {
var children = _ref.children,
_ref$encodeHashtag = _ref.encodeHashtag,
encodeHashtag = _ref$encodeHashtag === void 0 ? false : _ref$encodeHashtag,
hashtag = _ref.hashtag,
_ref$hashtagUrl = _ref.hashtagUrl,
hashtagUrl = _ref$hashtagUrl === void 0 ? '{{hashtag}}' : _ref$hashtagUrl,
_ref$preserveHash = _ref.preserveHash,
preserveHash = _ref$preserveHash === void 0 ? false : _ref$preserveHash,
props = _objectWithoutPropertiesLoose(_ref, ["children", "encodeHashtag", "hashtag", "hashtagUrl", "preserveHash"]);
var tag = hashtag;
if (!preserveHash && tag.charAt(0) === '#') {
tag = tag.slice(1);
}
if (encodeHashtag) {
tag = encodeURIComponent(tag);
}
var url = hashtagUrl || '{{hashtag}}';
if (typeof url === 'function') {
url = url(tag);
} else {
url = url.replace('{{hashtag}}', tag);
}
return React.createElement(Link, _extends({}, props, {
href: url
}), children);
}
var HashtagMatcher = function (_Matcher) {
_inheritsLoose(HashtagMatcher, _Matcher);
function HashtagMatcher() {
return _Matcher.apply(this, arguments) || this;
}
var _proto = HashtagMatcher.prototype;
_proto.replaceWith = function replaceWith(children, props) {
return React.createElement(Hashtag, props, children);
};
_proto.asTag = function asTag() {
return 'a';
};
_proto.match = function match(string) {
return this.doMatch(string, HASHTAG_PATTERN, function (matches) {
return {
hashtag: matches[0]
};
});
};
return HashtagMatcher;
}(Matcher);
function Url(_ref) {
var children = _ref.children,
url = _ref.url,
urlParts = _ref.urlParts,
props = _objectWithoutPropertiesLoose(_ref, ["children", "url", "urlParts"]);
var href = url;
if (!href.match(/^https?:\/\//)) {
href = "http://" + href;
}
return React.createElement(Link, _extends({}, props, {
href: href
}), children);
}
var UrlMatcher = function (_Matcher) {
_inheritsLoose(UrlMatcher, _Matcher);
function UrlMatcher(name, options, factory) {
return _Matcher.call(this, name, _extends({
customTLDs: [],
validateTLD: true
}, options), factory) || this;
}
var _proto = UrlMatcher.prototype;
_proto.replaceWith = function replaceWith(children, props) {
return React.createElement(Url, props, children);
};
_proto.asTag = function asTag() {
return 'a';
};
_proto.match = function match(string) {
var response = this.doMatch(string, URL_PATTERN, this.handleMatches);
if (response && response.match.match(EMAIL_DISTINCT_PATTERN)) {
response.valid = false;
}
if (response && this.options.validateTLD) {
var _ref = response.urlParts,
host = _ref.host;
var validList = TOP_LEVEL_TLDS.concat(this.options.customTLDs || []);
var tld = host.slice(host.lastIndexOf('.') + 1).toLowerCase();
if (!validList.includes(tld)) {
return null;
}
}
return response;
};
_proto.handleMatches = function handleMatches(matches) {
return {
url: matches[0],
urlParts: {
auth: matches[2] ? matches[2].slice(0, -1) : '',
fragment: matches[7] || '',
host: matches[3],
path: matches[5] || '',
port: matches[4] ? matches[4] : '',
query: matches[6] || '',
scheme: matches[1] ? matches[1].replace('://', '') : 'http'
}
};
};
return UrlMatcher;
}(Matcher);
var IpMatcher = function (_UrlMatcher) {
_inheritsLoose(IpMatcher, _UrlMatcher);
function IpMatcher(name, options, factory) {
return _UrlMatcher.call(this, name, _extends({}, options, {
validateTLD: false
}), factory) || this;
}
var _proto = IpMatcher.prototype;
_proto.match = function match(string) {
return this.doMatch(string, IP_PATTERN, this.handleMatches);
};
return IpMatcher;
}(UrlMatcher);
export { Email, EmailMatcher, Hashtag, HashtagMatcher, IpMatcher, Link, Url, UrlMatcher };

11

lib/Email.d.ts
/// <reference types="react" />
import { ChildrenNode } from 'interweave';
import { LinkProps } from './Link';
export interface EmailProps extends Partial<LinkProps> {
children: ChildrenNode;
email: string;
emailParts: {
host: string;
username: string;
};
}
import { EmailProps } from './types';
export default function Email({ children, email, emailParts, ...props }: EmailProps): JSX.Element;
//# sourceMappingURL=Email.d.ts.map
import { Matcher, MatchResponse, Node, ChildrenNode } from 'interweave';
import { EmailProps } from './Email';
import { EmailProps } from './types';
export declare type EmailMatch = Pick<EmailProps, 'email' | 'emailParts'>;

@@ -4,0 +4,0 @@ export default class EmailMatcher extends Matcher<EmailProps> {

/// <reference types="react" />
import { ChildrenNode } from 'interweave';
import { LinkProps } from './Link';
export interface HashtagProps extends Partial<LinkProps> {
children: ChildrenNode;
encodeHashtag?: boolean;
hashtag: string;
hashtagUrl?: string | ((hashtag: string) => string);
preserveHash?: boolean;
}
import { HashtagProps } from './types';
export default function Hashtag({ children, encodeHashtag, hashtag, hashtagUrl, preserveHash, ...props }: HashtagProps): JSX.Element;
//# sourceMappingURL=Hashtag.d.ts.map
import { Matcher, MatchResponse, Node, ChildrenNode } from 'interweave';
import { HashtagProps } from './Hashtag';
import { HashtagProps } from './types';
export declare type HashtagMatch = Pick<HashtagProps, 'hashtag'>;

@@ -4,0 +4,0 @@ export default class HashtagMatcher extends Matcher<HashtagProps> {

@@ -5,11 +5,12 @@ /**

*/
import Email, { EmailProps } from './Email';
import Email from './Email';
import EmailMatcher from './EmailMatcher';
import Hashtag, { HashtagProps } from './Hashtag';
import Hashtag from './Hashtag';
import HashtagMatcher from './HashtagMatcher';
import IpMatcher from './IpMatcher';
import Link, { LinkProps } from './Link';
import Url, { UrlProps } from './Url';
import UrlMatcher, { UrlMatcherOptions } from './UrlMatcher';
export { Email, EmailProps, EmailMatcher, Hashtag, HashtagProps, HashtagMatcher, IpMatcher, Link, LinkProps, Url, UrlProps, UrlMatcher, UrlMatcherOptions, };
import Link from './Link';
import Url from './Url';
import UrlMatcher from './UrlMatcher';
export { Email, EmailMatcher, Hashtag, HashtagMatcher, IpMatcher, Link, Url, UrlMatcher };
export * from './types';
//# sourceMappingURL=index.d.ts.map

@@ -1,46 +0,351 @@

"use strict";
'use strict';
exports.__esModule = true;
Object.defineProperty(exports, '__esModule', { value: true });
var _Email = _interopRequireWildcard(require("./Email"));
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
exports.Email = _Email.default;
exports.EmailProps = _Email.EmailProps;
var React = _interopDefault(require('react'));
var interweave = require('interweave');
var _EmailMatcher = _interopRequireDefault(require("./EmailMatcher"));
function _extends() {
_extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];
exports.EmailMatcher = _EmailMatcher.default;
for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}
var _Hashtag = _interopRequireWildcard(require("./Hashtag"));
return target;
};
exports.Hashtag = _Hashtag.default;
exports.HashtagProps = _Hashtag.HashtagProps;
return _extends.apply(this, arguments);
}
var _HashtagMatcher = _interopRequireDefault(require("./HashtagMatcher"));
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
subClass.__proto__ = superClass;
}
exports.HashtagMatcher = _HashtagMatcher.default;
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
var _IpMatcher = _interopRequireDefault(require("./IpMatcher"));
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
exports.IpMatcher = _IpMatcher.default;
return target;
}
var _Link = _interopRequireWildcard(require("./Link"));
function Link(_ref) {
var children = _ref.children,
href = _ref.href,
onClick = _ref.onClick,
newWindow = _ref.newWindow;
return React.createElement("a", {
href: href,
target: newWindow ? '_blank' : undefined,
onClick: onClick,
rel: "noopener noreferrer"
}, children);
}
exports.Link = _Link.default;
exports.LinkProps = _Link.LinkProps;
function Email(_ref) {
var children = _ref.children,
email = _ref.email,
emailParts = _ref.emailParts,
props = _objectWithoutPropertiesLoose(_ref, ["children", "email", "emailParts"]);
var _Url = _interopRequireWildcard(require("./Url"));
return React.createElement(Link, _extends({}, props, {
href: "mailto:" + email
}), children);
}
exports.Url = _Url.default;
exports.UrlProps = _Url.UrlProps;
function combinePatterns(patterns, options) {
if (options === void 0) {
options = {};
}
var _UrlMatcher = _interopRequireWildcard(require("./UrlMatcher"));
var regex = patterns.map(function (pattern) {
return pattern.source;
}).join(options.join || '');
exports.UrlMatcher = _UrlMatcher.default;
exports.UrlMatcherOptions = _UrlMatcher.UrlMatcherOptions;
if (options.capture) {
regex = "(" + regex + ")";
} else if (options.nonCapture) {
regex = "(?:" + regex + ")";
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
if (options.match) {
regex += options.match;
}
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
return new RegExp(regex, options.flags || '');
}
var VALID_ALNUM_CHARS = /[a-z0-9]/;
var VALID_PATH_CHARS = /(?:[a-zA-Z\u0400-\u04FF0-9\-_~!$&'()[\]\\/*+,;=.%]*)/;
var URL_SCHEME = /(https?:\/\/)?/;
var URL_AUTH = combinePatterns([/[a-z\u0400-\u04FF0-9\-_~!$&'()*+,;=.:]+/, /@/], {
capture: true,
match: '?'
});
var URL_HOST = combinePatterns([/(?:(?:[a-z0-9](?:[-a-z0-9_]*[a-z0-9])?)\.)*/, /(?:(?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?)\.)/, /(?:[a-z](?:[-a-z0-9]*[a-z0-9])?)/], {
capture: true
});
var URL_PORT = /(?::(\d{1,5}))?/;
var URL_PATH = combinePatterns([/\//, combinePatterns([/[-+a-z0-9!*';:=,.$/%[\]_~@|&]*/, /[-+a-z0-9/]/], {
match: '*',
nonCapture: true
})], {
capture: true,
match: '?'
});
var URL_QUERY = combinePatterns([/\?/, combinePatterns([VALID_PATH_CHARS, /[a-z0-9_&=]/], {
match: '?',
nonCapture: true
})], {
capture: true,
match: '?'
});
var URL_FRAGMENT = combinePatterns([/#/, combinePatterns([VALID_PATH_CHARS, /[a-z0-9]/], {
match: '?',
nonCapture: true
})], {
capture: true,
match: '?'
});
var URL_PATTERN = combinePatterns([URL_SCHEME, URL_AUTH, URL_HOST, URL_PORT, URL_PATH, URL_QUERY, URL_FRAGMENT], {
flags: 'i'
});
var IP_V4_PART = /(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/;
var IP_V4 = combinePatterns([IP_V4_PART, IP_V4_PART, IP_V4_PART, IP_V4_PART], {
capture: true,
join: '\\.'
});
var IP_PATTERN = combinePatterns([URL_SCHEME, URL_AUTH, IP_V4, URL_PORT, URL_PATH, URL_QUERY, URL_FRAGMENT], {
flags: 'i'
});
var HASHTAG_PATTERN = combinePatterns([/#/, combinePatterns([VALID_ALNUM_CHARS, /[-a-z0-9_]*/, VALID_ALNUM_CHARS], {
capture: true
})], {
flags: 'i'
});
var EMAIL_USERNAME_PART = /[a-z0-9!#$%&?*+=_{|}~-]+/;
var EMAIL_USERNAME = combinePatterns([VALID_ALNUM_CHARS, EMAIL_USERNAME_PART, VALID_ALNUM_CHARS, combinePatterns([/\./, VALID_ALNUM_CHARS, EMAIL_USERNAME_PART, VALID_ALNUM_CHARS], {
match: '?',
nonCapture: true
})], {
capture: true
});
var EMAIL_PATTERN = combinePatterns([EMAIL_USERNAME, URL_HOST], {
flags: 'i',
join: '@'
});
var EMAIL_DISTINCT_PATTERN = new RegExp("^" + EMAIL_PATTERN.source + "$", EMAIL_PATTERN.flags);
var TOP_LEVEL_TLDS = ['com', 'org', 'net', 'int', 'edu', 'gov', 'mil', 'aero', 'asia', 'cat', 'coop', 'jobs', 'mobi', 'museum', 'post', 'tel', 'travel', 'xxx', 'arpa', 'test', 'ac', 'ad', 'ae', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'as', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb', 'bd', 'be', 'bf', 'bg', 'bh', 'bi', 'bj', 'bl', 'bm', 'bn', 'bo', 'bq', 'br', 'bs', 'bt', 'bv', 'bw', 'by', 'bz', 'ca', 'cc', 'cd', 'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'cr', 'cu', 'cv', 'cw', 'cx', 'cy', 'cz', 'de', 'dj', 'dk', 'dm', 'do', 'dz', 'ec', 'ee', 'eg', 'eh', 'er', 'es', 'et', 'eu', 'fi', 'fj', 'fk', 'fm', 'fo', 'fr', 'ga', 'gb', 'gd', 'ge', 'gf', 'gg', 'gh', 'gi', 'gl', 'gm', 'gn', 'gp', 'gq', 'gr', 'gs', 'gt', 'gu', 'gw', 'gy', 'hk', 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'im', 'in', 'io', 'iq', 'ir', 'is', 'it', 'je', 'jm', 'jo', 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kp', 'kr', 'kw', 'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'lr', 'ls', 'lt', 'lu', 'lv', 'ly', 'ma', 'mc', 'md', 'me', 'mf', 'mg', 'mh', 'mk', 'ml', 'mm', 'mn', 'mo', 'mp', 'mq', 'mr', 'ms', 'mt', 'mu', 'mv', 'mw', 'mx', 'my', 'mz', 'na', 'nc', 'ne', 'nf', 'ng', 'ni', 'nl', 'no', 'np', 'nr', 'nu', 'nz', 'om', 'pa', 'pe', 'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'ps', 'pt', 'pw', 'py', 'qa', 're', 'ro', 'rs', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd', 'se', 'sg', 'sh', 'si', 'sj', 'sk', 'sl', 'sm', 'sn', 'so', 'sr', 'st', 'su', 'sv', 'sx', 'sy', 'sz', 'tc', 'td', 'tf', 'tg', 'th', 'tj', 'tk', 'tl', 'tm', 'tn', 'to', 'tp', 'tr', 'tt', 'tv', 'tw', 'tz', 'ua', 'ug', 'uk', 'um', 'us', 'uy', 'uz', 'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', 'wf', 'ws', 'ye', 'yt', 'za', 'zm', 'zw'];
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var EmailMatcher = function (_Matcher) {
_inheritsLoose(EmailMatcher, _Matcher);
function EmailMatcher() {
return _Matcher.apply(this, arguments) || this;
}
var _proto = EmailMatcher.prototype;
_proto.replaceWith = function replaceWith(children, props) {
return React.createElement(Email, props, children);
};
_proto.asTag = function asTag() {
return 'a';
};
_proto.match = function match(string) {
return this.doMatch(string, EMAIL_PATTERN, function (matches) {
return {
email: matches[0],
emailParts: {
host: matches[2],
username: matches[1]
}
};
});
};
return EmailMatcher;
}(interweave.Matcher);
function Hashtag(_ref) {
var children = _ref.children,
_ref$encodeHashtag = _ref.encodeHashtag,
encodeHashtag = _ref$encodeHashtag === void 0 ? false : _ref$encodeHashtag,
hashtag = _ref.hashtag,
_ref$hashtagUrl = _ref.hashtagUrl,
hashtagUrl = _ref$hashtagUrl === void 0 ? '{{hashtag}}' : _ref$hashtagUrl,
_ref$preserveHash = _ref.preserveHash,
preserveHash = _ref$preserveHash === void 0 ? false : _ref$preserveHash,
props = _objectWithoutPropertiesLoose(_ref, ["children", "encodeHashtag", "hashtag", "hashtagUrl", "preserveHash"]);
var tag = hashtag;
if (!preserveHash && tag.charAt(0) === '#') {
tag = tag.slice(1);
}
if (encodeHashtag) {
tag = encodeURIComponent(tag);
}
var url = hashtagUrl || '{{hashtag}}';
if (typeof url === 'function') {
url = url(tag);
} else {
url = url.replace('{{hashtag}}', tag);
}
return React.createElement(Link, _extends({}, props, {
href: url
}), children);
}
var HashtagMatcher = function (_Matcher) {
_inheritsLoose(HashtagMatcher, _Matcher);
function HashtagMatcher() {
return _Matcher.apply(this, arguments) || this;
}
var _proto = HashtagMatcher.prototype;
_proto.replaceWith = function replaceWith(children, props) {
return React.createElement(Hashtag, props, children);
};
_proto.asTag = function asTag() {
return 'a';
};
_proto.match = function match(string) {
return this.doMatch(string, HASHTAG_PATTERN, function (matches) {
return {
hashtag: matches[0]
};
});
};
return HashtagMatcher;
}(interweave.Matcher);
function Url(_ref) {
var children = _ref.children,
url = _ref.url,
urlParts = _ref.urlParts,
props = _objectWithoutPropertiesLoose(_ref, ["children", "url", "urlParts"]);
var href = url;
if (!href.match(/^https?:\/\//)) {
href = "http://" + href;
}
return React.createElement(Link, _extends({}, props, {
href: href
}), children);
}
var UrlMatcher = function (_Matcher) {
_inheritsLoose(UrlMatcher, _Matcher);
function UrlMatcher(name, options, factory) {
return _Matcher.call(this, name, _extends({
customTLDs: [],
validateTLD: true
}, options), factory) || this;
}
var _proto = UrlMatcher.prototype;
_proto.replaceWith = function replaceWith(children, props) {
return React.createElement(Url, props, children);
};
_proto.asTag = function asTag() {
return 'a';
};
_proto.match = function match(string) {
var response = this.doMatch(string, URL_PATTERN, this.handleMatches);
if (response && response.match.match(EMAIL_DISTINCT_PATTERN)) {
response.valid = false;
}
if (response && this.options.validateTLD) {
var _ref = response.urlParts,
host = _ref.host;
var validList = TOP_LEVEL_TLDS.concat(this.options.customTLDs || []);
var tld = host.slice(host.lastIndexOf('.') + 1).toLowerCase();
if (!validList.includes(tld)) {
return null;
}
}
return response;
};
_proto.handleMatches = function handleMatches(matches) {
return {
url: matches[0],
urlParts: {
auth: matches[2] ? matches[2].slice(0, -1) : '',
fragment: matches[7] || '',
host: matches[3],
path: matches[5] || '',
port: matches[4] ? matches[4] : '',
query: matches[6] || '',
scheme: matches[1] ? matches[1].replace('://', '') : 'http'
}
};
};
return UrlMatcher;
}(interweave.Matcher);
var IpMatcher = function (_UrlMatcher) {
_inheritsLoose(IpMatcher, _UrlMatcher);
function IpMatcher(name, options, factory) {
return _UrlMatcher.call(this, name, _extends({}, options, {
validateTLD: false
}), factory) || this;
}
var _proto = IpMatcher.prototype;
_proto.match = function match(string) {
return this.doMatch(string, IP_PATTERN, this.handleMatches);
};
return IpMatcher;
}(UrlMatcher);
exports.Email = Email;
exports.EmailMatcher = EmailMatcher;
exports.Hashtag = Hashtag;
exports.HashtagMatcher = HashtagMatcher;
exports.IpMatcher = IpMatcher;
exports.Link = Link;
exports.Url = Url;
exports.UrlMatcher = UrlMatcher;
import React from 'react';
import { MatchResponse } from 'interweave';
import { UrlProps } from './Url';
import UrlMatcher, { UrlMatch, UrlMatcherOptions } from './UrlMatcher';
import UrlMatcher, { UrlMatch } from './UrlMatcher';
import { UrlMatcherOptions, UrlProps } from './types';
export default class IpMatcher extends UrlMatcher {

@@ -6,0 +6,0 @@ constructor(name: string, options?: UrlMatcherOptions, factory?: React.ComponentType<UrlProps> | null);

@@ -1,10 +0,4 @@

import React from 'react';
export interface LinkProps {
children: React.ReactNode;
href: string;
key?: string | number;
newWindow?: boolean;
onClick?: () => void | null;
}
/// <reference types="react" />
import { LinkProps } from './types';
export default function Link({ children, href, onClick, newWindow }: LinkProps): JSX.Element;
//# sourceMappingURL=Link.d.ts.map
/// <reference types="react" />
import { ChildrenNode } from 'interweave';
import { LinkProps } from './Link';
export interface UrlProps extends Partial<LinkProps> {
children: ChildrenNode;
url: string;
urlParts: {
auth: string;
fragment: string;
host: string;
path: string;
port: string | number;
query: string;
scheme: string;
};
}
import { UrlProps } from './types';
export default function Url({ children, url, urlParts, ...props }: UrlProps): JSX.Element;
//# sourceMappingURL=Url.d.ts.map
import React from 'react';
import { Matcher, MatchResponse, Node, ChildrenNode } from 'interweave';
import { UrlProps } from './Url';
import { UrlProps, UrlMatcherOptions } from './types';
export declare type UrlMatch = Pick<UrlProps, 'url' | 'urlParts'>;
export interface UrlMatcherOptions {
customTLDs?: string[];
validateTLD?: boolean;
}
export default class UrlMatcher extends Matcher<UrlProps, UrlMatcherOptions> {

@@ -10,0 +6,0 @@ constructor(name: string, options?: UrlMatcherOptions, factory?: React.ComponentType<UrlProps> | null);

{
"name": "interweave-autolink",
"version": "4.0.1",
"version": "4.1.0",
"description": "URL, IP, email, and hashtag autolinking support for Interweave.",

@@ -15,3 +15,3 @@ "keywords": [

"main": "./lib/index.js",
"module": "./module.js",
"module": "./esm/index.js",
"types": "./lib/index.d.ts",

@@ -34,3 +34,3 @@ "sideEffects": false,

"interweave-ssr": "^1.0.0",
"react": "^16.11.0"
"react": "^16.12.0"
},

@@ -41,3 +41,3 @@ "funding": {

},
"gitHead": "94b445d42f614e06418c9843cc7d576bb825f836"
"gitHead": "746a3dd3cd2be78848e3bc829f02581edd915dec"
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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