Socket
Socket
Sign inDemoInstall

react-linkify

Package Overview
Dependencies
45
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1 to 0.1.2

.babelrc

141

dist/Linkify.js
'use strict';
Object.defineProperty(exports, '__esModule', {
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
var _react = require('react');

@@ -27,18 +21,30 @@

var linkify = new _linkifyIt2['default']();
linkify.tlds(_tlds2['default']);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var Linkify = (function (_React$Component) {
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
var linkify = new _linkifyIt2.default();
linkify.tlds(_tlds2.default);
var Linkify = function (_React$Component) {
_inherits(Linkify, _React$Component);
function Linkify() {
var _Object$getPrototypeO;
var _temp, _this, _ret;
_classCallCheck(this, Linkify);
if (_React$Component != null) {
_React$Component.apply(this, arguments);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
this.parseCounter = 0;
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(Linkify)).call.apply(_Object$getPrototypeO, [this].concat(args))), _this), _this.parseCounter = 0, _temp), _possibleConstructorReturn(_this, _ret);
}
_inherits(Linkify, _React$Component);
_createClass(Linkify, [{

@@ -52,2 +58,4 @@ key: 'getMatches',

value: function parseString(string) {
var _this2 = this;
var elements = [];

@@ -64,42 +72,20 @@ if (string === '') {

var lastIndex = 0;
var idx = 0;
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = matches[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var match = _step.value;
// Push the preceding text if there is any
if (match.index > lastIndex) {
elements.push(string.substring(lastIndex, match.index));
matches.forEach(function (match, idx) {
// Push the preceding text if there is any
if (match.index > lastIndex) {
elements.push(string.substring(lastIndex, match.index));
}
// Shallow update values that specified the match
var props = { href: match.url, key: 'parse' + _this2.parseCounter + 'match' + idx };
for (var key in _this2.props.properties) {
var val = _this2.props.properties[key];
if (val === Linkify.MATCH) {
val = match.url;
}
// Shallow update values that specified the match
var props = { href: match.url, key: 'match' + ++idx };
for (var key in this.props.properties) {
var val = this.props.properties[key];
if (val === Linkify.MATCH) {
val = match.url;
}
props[key] = val;
}
elements.push(_react2['default'].createElement(this.props.component, props, match.text));
lastIndex = match.lastIndex;
props[key] = val;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator['return']) {
_iterator['return']();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
elements.push(_react2.default.createElement(_this2.props.component, props, match.text));
lastIndex = match.lastIndex;
});

@@ -115,3 +101,3 @@ if (lastIndex < string.length) {

value: function parse(children) {
var _this = this;
var _this3 = this;

@@ -122,7 +108,7 @@ var parsed = children;

parsed = this.parseString(children);
} else if (_react2['default'].isValidElement(children) && children.type !== 'a' && children.type !== 'button') {
parsed = _react2['default'].cloneElement(children, { key: 'parse' + ++this.parseCounter }, this.parse(children.props.children));
} else if (_react2.default.isValidElement(children) && children.type !== 'a' && children.type !== 'button') {
parsed = _react2.default.cloneElement(children, { key: 'parse' + ++this.parseCounter }, this.parse(children.props.children));
} else if (children instanceof Array) {
parsed = children.map(function (child) {
return _this.parse(child);
return _this3.parse(child);
});

@@ -139,33 +125,26 @@ }

return _react2['default'].createElement(
return _react2.default.createElement(
'span',
{ className: 'Linkify' },
{ className: this.props.className },
parsedChildren
);
}
}], [{
key: 'MATCH',
value: 'LINKIFY_MATCH',
enumerable: true
}, {
key: 'propTypes',
value: {
component: _react2['default'].PropTypes.any,
properties: _react2['default'].PropTypes.object,
urlRegex: _react2['default'].PropTypes.object,
emailRegex: _react2['default'].PropTypes.object
},
enumerable: true
}, {
key: 'defaultProps',
value: {
component: 'a',
properties: {} },
enumerable: true
}]);
return Linkify;
})(_react2['default'].Component);
}(_react2.default.Component);
exports['default'] = Linkify;
module.exports = exports['default'];
Linkify.MATCH = 'LINKIFY_MATCH';
Linkify.propTypes = {
className: _react2.default.PropTypes.string,
component: _react2.default.PropTypes.any,
properties: _react2.default.PropTypes.object,
urlRegex: _react2.default.PropTypes.object,
emailRegex: _react2.default.PropTypes.object
};
Linkify.defaultProps = {
className: 'Linkify',
component: 'a',
properties: {}
};
exports.default = Linkify;
{
"name": "react-linkify",
"version": "0.1.1",
"version": "0.1.2",
"description": "React component to parse links (urls, emails, etc.) in text into clickable links",

@@ -26,10 +26,13 @@ "homepage": "http://tasti.github.io/react-linkify/",

"scripts": {
"build": "babel --stage 0 src/Linkify.jsx -o dist/Linkify.js",
"build": "babel src/Linkify.jsx -o dist/Linkify.js",
"test": "BABEL_JEST_STAGE=0 jest"
},
"devDependencies": {
"babel-jest": "~5.3.0",
"jest": "^0.1.40",
"jest-cli": "~0.7.1",
"react": "~0.14.2",
"babel-cli": "^6.7.7",
"babel-jest": "^12.1.0",
"babel-plugin-transform-react-jsx": "^6.7.5",
"babel-preset-es2015": "^6.6.0",
"babel-preset-stage-0": "^6.5.0",
"jest": "^12.1.1",
"jest-cli": "^12.1.1",
"react-addons-test-utils": "~0.14.2"

@@ -42,4 +45,5 @@ },

"linkify-it": "^1.2.0",
"react": "~0.14.2",
"tlds": "^1.57.0"
}
}

@@ -7,3 +7,3 @@ jest.autoMockOff();

describe('Linkify', () => {
let Linkify = require('../Linkify.jsx');
let Linkify = require('../Linkify.jsx').default;

@@ -126,3 +126,13 @@ describe('#parseString', () => {

describe('#render', () => {
let linkify = TestUtils.renderIntoDocument(<Linkify></Linkify>);
it('should render with default className of Linkify if one is not provided', () => {
expect(linkify.props.className).toEqual('Linkify');
});
it('should render with a custom className if one is provided', () => {
let linkify = TestUtils.renderIntoDocument(<Linkify className="custom-class"></Linkify>);
expect(linkify.props.className).toEqual('custom-class');
});
});

@@ -129,0 +139,0 @@

@@ -12,2 +12,3 @@ import React from 'react';

static propTypes = {
className: React.PropTypes.string,
component: React.PropTypes.any,

@@ -20,2 +21,3 @@ properties: React.PropTypes.object,

static defaultProps = {
className: 'Linkify',
component: 'a',

@@ -43,4 +45,3 @@ properties: {},

let lastIndex = 0;
let idx = 0;
for (let match of matches) {
matches.forEach((match, idx) => {
// Push the preceding text if there is any

@@ -51,3 +52,3 @@ if (match.index > lastIndex) {

// Shallow update values that specified the match
let props = {href: match.url, key: `match${++idx}`};
let props = {href: match.url, key: `parse${this.parseCounter}match${idx}`};
for (let key in this.props.properties) {

@@ -67,3 +68,3 @@ let val = this.props.properties[key];

lastIndex = match.lastIndex;
}
});

@@ -101,3 +102,3 @@ if (lastIndex < string.length) {

return <span className="Linkify">{parsedChildren}</span>;
return <span className={this.props.className}>{parsedChildren}</span>;
}

@@ -104,0 +105,0 @@ }

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc