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

ansi-to-react

Package Overview
Dependencies
Maintainers
4
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ansi-to-react - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

27

lib/index.js

@@ -48,19 +48,12 @@ 'use strict';

return _extends({}, bundle, {
content: bundle.content.split(' ').reduce(function (result, word) {
// If word is a URL
if (/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/.test(word)) {
return [].concat(_toConsumableArray(result), [' ', React.createElement('a', {
href: word,
target: '_blank'
}, '' + word)]);
}
var lastWord = result.pop();
if (lastWord) {
// If lastWord is a `<a>` element
if (lastWord.type) return [].concat(_toConsumableArray(result), [lastWord, ' ', word]);
// If not, combine lastWord and word into single string
return [].concat(_toConsumableArray(result), [[lastWord, word].join(' ')]);
}
// If there is no lastWord because word is the first
return [].concat(_toConsumableArray(result), [word]);
content: bundle.content.split(' ').reduce(function (result, word, index) {
return [].concat(_toConsumableArray(result), [
// Unless word is the first, prepend a space
index === 0 ? '' : ' ',
// If word is a URL, return an <a> element
/(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/.test(word) ? React.createElement('a', {
key: index,
href: word,
target: '_blank'
}, '' + word) : word]);
}, [])

@@ -67,0 +60,0 @@ });

{
"name": "ansi-to-react",
"version": "1.1.1",
"version": "1.2.0",
"description": "ANSI to React Elements",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -43,28 +43,20 @@ const React = require('react');

...bundle,
content: bundle.content.split(' ').reduce(
(result, word) => {
// If word is a URL
if (/[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/.test(word)) {
return [
...result,
' ',
React.createElement('a', {
href: word ,
content: bundle.content.split(' ').reduce((result, word, index) => [
...result,
// Unless word is the first, prepend a space
index === 0 ? '' : ' ',
// If word is a URL, return an <a> element
/(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})/.test(word)
? React.createElement(
'a',
{
key: index,
href: word,
target: '_blank'
}, `${word}`)
];
}
const lastWord = result.pop();
if (lastWord) {
// If lastWord is a `<a>` element
if (lastWord.type) return [...result, lastWord, ' ', word];
// If not, combine lastWord and word into single string
return [...result, [lastWord, word].join(' ')];
}
// If there is no lastWord because word is the first
return [...result, word];
},
[]
)
}
},
`${word}`
)
: word
], [])
};
}

@@ -71,0 +63,0 @@

@@ -43,2 +43,14 @@ const Ansi = require('../src/index');

});
it('can distinguish URL-ish text', () => {
const el = enzyme.shallow(React.createElement(Ansi, {linkify: true}, '<transport.model.TransportInfo'));
expect(el).to.not.be.null;
expect(el.text()).to.equal('<transport.model.TransportInfo');
});
it('can distinguish URL-ish text', () => {
const el = enzyme.shallow(React.createElement(Ansi, {linkify: true}, "<module 'something' from '/usr/local/lib/python2.7/dist-packages/something/__init__.pyc'>"));
expect(el).to.not.be.null;
expect(el.text()).to.equal("<module 'something' from '/usr/local/lib/python2.7/dist-packages/something/__init__.pyc'>");
});
});

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