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 0.0.6 to 1.0.0

22

lib/index.js
'use strict';
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
var React = require('react');

@@ -43,6 +45,24 @@ var Anser = require('anser');

function inlineBundleToReact(bundle, key) {
var children = 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]);
}, []);
return React.createElement('span', {
style: bundle.style,
key: key
}, bundle.content);
}, children);
}

@@ -49,0 +69,0 @@

2

package.json
{
"name": "ansi-to-react",
"version": "0.0.6",
"version": "1.0.0",
"description": "ANSI to React Elements",

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

@@ -41,6 +41,30 @@ const React = require('react');

function inlineBundleToReact(bundle, key) {
const children = 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 ,
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];
},
[]
);
return React.createElement('span', {
style: bundle.style,
key,
}, bundle.content);
}, children);
}

@@ -47,0 +71,0 @@

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