ansi-to-react
Advanced tools
Comparing version 0.0.6 to 1.0.0
'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 @@ |
{ | ||
"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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
12070
174
1
1