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

ansi-html-themed

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ansi-html-themed - npm Package Compare versions

Comparing version 0.0.0 to 0.1.0

115

lib/index.js

@@ -6,78 +6,75 @@ 'use strict';

});
exports.parse = undefined;
exports.generateAnsiHtml = undefined;
var _stackFrame = require('stack-frame');
var _anser = require('anser');
var _stackFrame2 = _interopRequireDefault(_stackFrame);
var _anser2 = _interopRequireDefault(_anser);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 base01 = 'f5f5f5',
base03 = '969896',
base05 = '333333',
base08 = 'ed6a43',
base0B = '183691',
base0C = '183691',
base0E = 'a71d5d';
var regexExtractLocation = /\(?(.+?)(?::(\d+))?(?::(\d+))?\)?$/;
function extractLocation(token) {
return regexExtractLocation.exec(token).slice(1).map(function (v) {
var p = Number(v);
if (!isNaN(p)) {
return p;
}
return v;
var defaultColors = {
reset: [base05, 'transparent'],
black: base05,
red: base08 /* marker, bg-invalid */
, green: base0B /* string */
, yellow: base08 /* capitalized, jsx_tag, punctuator */
, blue: base0C,
magenta: base0C /* regex */
, cyan: base0E /* keyword */
, gray: base03 /* comment, gutter */
, lightgrey: base01,
darkgrey: base03
};
function generateAnsiHtml(text) {
var colors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
colors = Object.assign({}, defaultColors, colors);
var arr = new _anser2.default().ansiToJson(text, {
use_classes: true
});
}
var regexValidFrame_Chrome = /^\s*(at|in)\s.+(:\d+)/;
var regexValidFrame_FireFox = /(^|@)\S+:\d+|.+line\s+\d+\s+>\s+(eval|Function).+/;
var result = '';
var open = false;
for (var index = 0; index < arr.length; ++index) {
var c = arr[index];
var content = c.content,
fg = c.fg;
function parseStack(stack) {
var frames = stack.filter(function (e) {
return regexValidFrame_Chrome.test(e) || regexValidFrame_FireFox.test(e);
}).map(function (e) {
if (regexValidFrame_FireFox.test(e)) {
// Strip eval, we don't care about it
var isEval = false;
if (/ > (eval|Function)/.test(e)) {
e = e.replace(/ line (\d+)(?: > eval line \d+)* > (eval|Function):\d+:\d+/g, ':$1');
isEval = true;
var contentParts = content.split('\n');
for (var _index = 0; _index < contentParts.length; ++_index) {
if (!open) {
result += '<span data-ansi-line="true">';
open = true;
}
var data = e.split(/[@]/g);
var last = data.pop();
return new (Function.prototype.bind.apply(_stackFrame2.default, [null].concat([data.join('@') || (isEval ? 'eval' : null)], _toConsumableArray(extractLocation(last)))))();
} else {
// Strip eval, we don't care about it
if (e.indexOf('(eval ') !== -1) {
e = e.replace(/(\(eval at [^()]*)|(\),.*$)/g, '');
var part = contentParts[_index].replace('\r', '');
var color = fg == null ? null : colors[fg] || colors[fg.replace(/^ansi-(bright-)?/, '')];
if (color != null) {
result += '<span style="color: #' + color + ';">' + part + '</span>';
} else {
result += '<span>' + part + '</span>';
}
if (e.indexOf('(at ') !== -1) {
e = e.replace(/\(at /, '(');
if (_index < contentParts.length - 1) {
result += '</span>';
open = false;
result += '<br/>';
}
var _data = e.trim().split(/\s+/g).slice(1);
var _last = _data.pop();
return new (Function.prototype.bind.apply(_stackFrame2.default, [null].concat([_data.join(' ') || null], _toConsumableArray(extractLocation(_last)))))();
}
});
return frames;
}
/**
* Turns an <code>Error</code>, or similar object, into a set of <code>{@link https://github.com/Timer/stack-frame/tree/master/packages/stack-frame#stackframe StackFrame}</code>s.
* @alias parse
*/
function parseError(error) {
if (error == null) {
throw new Error('You cannot pass a null object.');
}
if (typeof error === 'string') {
return parseStack(error.split('\n'));
if (open) {
result += '</span>';
open = false;
}
if (Array.isArray(error)) {
return parseStack(error);
}
if (typeof error.stack === 'string') {
return parseStack(error.stack.split('\n'));
}
throw new Error('The error you provided does not contain a stack trace.');
return result;
}
exports.parse = parseError;
exports.default = parseError;
exports.generateAnsiHtml = generateAnsiHtml;
{
"name": "ansi-html-themed",
"version": "0.0.0",
"version": "0.1.0",
"description": "Turns chalked code into pretty html.",

@@ -5,0 +5,0 @@ "scripts": {

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