ansi-to-json
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -1,1 +0,169 @@ | ||
"use strict";function _classCallCheck(e,n){if(!(e instanceof n))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function e(e,n){for(var r=0;r<n.length;r++){var t=n[r];t.enumerable=t.enumerable||!1,t.configurable=!0,"value"in t&&(t.writable=!0),Object.defineProperty(e,t.key,t)}}return function(n,r,t){return r&&e(n.prototype,r),t&&e(n,t),n}}(),_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};!function(e){if("object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.ansiToJson=e()}}(function(){return function e(n,r,t){function o(i,u){if(!r[i]){if(!n[i]){var l="function"==typeof require&&require;if(!u&&l)return l(i,!0);if(s)return s(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var c=r[i]={exports:{}};n[i][0].call(c.exports,function(e){var r=n[i][1][e];return o(r?r:e)},c,c.exports,e,n,r,t)}return r[i].exports}for(var s="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}({1:[function(e,n){function r(){a=!1,i.length?l=i.concat(l):c=-1,l.length&&t()}function t(){if(!a){var e=setTimeout(r);a=!0;for(var n=l.length;n;){for(i=l,l=[];++c<n;)i&&i[c].run();c=-1,n=l.length}i=null,a=!1,clearTimeout(e)}}function o(e,n){this.fun=e,this.array=n}function s(){}var i,u=n.exports={},l=[],a=!1,c=-1;u.nextTick=function(e){var n=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)n[r-1]=arguments[r];l.push(new o(e,n)),1!==l.length||a||setTimeout(t,0)},o.prototype.run=function(){this.fun.apply(null,this.array)},u.title="browser",u.browser=!0,u.env={},u.argv=[],u.version="",u.versions={},u.on=s,u.addListener=s,u.once=s,u.off=s,u.removeListener=s,u.removeAllListeners=s,u.emit=s,u.binding=function(){throw new Error("process.binding is not supported")},u.cwd=function(){return"/"},u.chdir=function(){throw new Error("process.chdir is not supported")},u.umask=function(){return 0}},{}],2:[function(e,n){function r(e){return t.ansiToJson(e,{json:!0,remove_empty:!0})}var t=e("anser");n.exports=r},{anser:3}],3:[function(e,n){(function(){var e=[[{color:"0, 0, 0","class":"ansi-black"},{color:"187, 0, 0","class":"ansi-red"},{color:"0, 187, 0","class":"ansi-green"},{color:"187, 187, 0","class":"ansi-yellow"},{color:"0, 0, 187","class":"ansi-blue"},{color:"187, 0, 187","class":"ansi-magenta"},{color:"0, 187, 187","class":"ansi-cyan"},{color:"255,255,255","class":"ansi-white"}],[{color:"85, 85, 85","class":"ansi-bright-black"},{color:"255, 85, 85","class":"ansi-bright-red"},{color:"0, 255, 0","class":"ansi-bright-green"},{color:"255, 255, 85","class":"ansi-bright-yellow"},{color:"85, 85, 255","class":"ansi-bright-blue"},{color:"255, 85, 255","class":"ansi-bright-magenta"},{color:"85, 255, 255","class":"ansi-bright-cyan"},{color:"255, 255, 255","class":"ansi-bright-white"}]];n.exports=function(){function n(){_classCallCheck(this,n),this.fg=this.bg=this.fg_truecolor=this.bg_truecolor=null,this.bright=0}return _createClass(n,null,[{key:"escapeForHtml",value:function(e){return(new n).escapeForHtml(e)}},{key:"linkify",value:function(e){return(new n).linkify(e)}},{key:"ansiToHtml",value:function(e,r){return(new n).ansiToHtml(e,r)}},{key:"ansiToJson",value:function(e,r){return(new n).ansiToJson(e,r)}},{key:"ansiToText",value:function(e){return(new n).ansiToText(e)}}]),_createClass(n,[{key:"setupPalette",value:function(){this.PALETTE_COLORS=[];for(var n=0;2>n;++n)for(var r=0;8>r;++r)this.PALETTE_COLORS.push(e[n][r].color);for(var t=[0,95,135,175,215,255],o=function(e,n,r){return t[e]+", "+t[n]+", "+t[r]},s=0;6>s;++s)for(var i=0;6>i;++i)for(var u=0;6>u;++u)this.PALETTE_COLORS.push(o(s,i,u));for(var l=8,a=0;24>a;++a,l+=10)this.PALETTE_COLORS.push(o(l,l,l))}},{key:"escapeForHtml",value:function(e){return e.replace(/[&<>]/gm,function(e){return"&"==e?"&":"<"==e?"<":">"==e?">":""})}},{key:"linkify",value:function(e){return e.replace(/(https?:\/\/[^\s]+)/gm,function(e){return'<a href="'+e+'">'+e+"</a>"})}},{key:"ansiToHtml",value:function(e,n){return this.process(e,n,!0)}},{key:"ansiToJson",value:function(e,n){return n=n||{},n.json=!0,this.process(e,n,!0)}},{key:"ansiToText",value:function(e){return this.process(e,{},!1)}},{key:"process",value:function(e,n,r){var t=this,o=this,s=e.split(/\033\[/),i=s.shift(),u=s.map(function(e){return t.processChunk(e,n,r)});if(n&&n.json){var l=o.processChunkJson("");return l.content=i,u.unshift(l),n.remove_empty&&(u=u.filter(function(e){return!e.isEmpty()})),u}return u.unshift(i),u.join("")}},{key:"processChunkJson",value:function(n,r,t){r="undefined"==typeof r?{}:r;var o=r.use_classes="undefined"!=typeof r.use_classes&&r.use_classes,s=r.key=o?"class":"color",i={content:n,fg:null,bg:null,fg_truecolor:null,bg_truecolor:null,was_processed:!1,isEmpty:function(){return!i.content}},u=n.match(/^([!\x3c-\x3f]*)([\d;]*)([\x20-\x2c]*[\x40-\x7e])([\s\S]*)/m);if(!u)return i;var l=(i.content=u[4],u[2].split(";"));if(""!==u[1]||"m"!==u[3])return i;if(!t)return i;for(var a=this;l.length>0;){var c=l.shift(),f=parseInt(c);if(isNaN(f)||0===f)a.fg=a.bg=null,a.bright=0;else if(1===f)a.bright=1;else if(39==f)a.fg=null;else if(49==f)a.bg=null;else if(f>=30&&38>f)a.fg=e[a.bright][f%10][s];else if(f>=90&&98>f)a.fg=e[1][f%10][s];else if(f>=40&&48>f)a.bg=e[0][f%10][s];else if(f>=100&&108>f)a.bg=e[1][f%10][s];else if(38===f||48===f){var g=38===f;if(l.length>=1){var p=l.shift();if("5"===p&&l.length>=1){var h=parseInt(l.shift());if(h>=0&&255>=h)if(o){var b=h>=16?"ansi-palette-"+h:e[h>7?1:0][h%8]["class"];g?a.fg=b:a.bg=b}else this.PALETTE_COLORS||a.setupPalette(),g?a.fg=this.PALETTE_COLORS[h]:a.bg=this.PALETTE_COLORS[h]}else if("2"===p&&l.length>=3){var v=parseInt(l.shift()),y=parseInt(l.shift()),d=parseInt(l.shift());if(v>=0&&255>=v&&y>=0&&255>=y&&d>=0&&255>=d){var m=v+", "+y+", "+d;o?g?(a.fg="ansi-truecolor",a.fg_truecolor=m):(a.bg="ansi-truecolor",a.bg_truecolor=m):g?a.fg=m:a.bg=m}}}}}if(null===a.fg&&null===a.bg)return i;return i.fg=a.fg,i.bg=a.bg,i.fg_truecolor=a.fg_truecolor,i.bg_truecolor=a.bg_truecolor,i.was_processed=!0,i}},{key:"processChunk",value:function(e,n,r){var t=this;n=n||{};var o=this.processChunkJson(e,n,r);if(n.json)return o;if(o.isEmpty())return"";if(!o.was_processed)return o.content;var s=n.use_classes,i=[],u=[],l={},a=function(e){var n=[],r=void 0;for(r in e)e.hasOwnProperty(r)&&n.push("data-"+r+'="'+t.escapeForHtml(e[r])+'"');return n.length>0?" "+n.join(" "):""};return o.fg&&(s?(u.push(o.fg+"-fg"),null!==o.fg_truecolor&&(l["ansi-truecolor-fg"]=o.fg_truecolor,o.fg_truecolor=null)):i.push("color:rgb("+o.fg+")")),o.bg&&(s?(u.push(o.bg+"-bg"),null!==o.bg_truecolor&&(l["ansi-truecolor-bg"]=o.bg_truecolor,o.bg_truecolor=null)):i.push("background-color:rgb("+o.bg+")")),s?'<span class="'+u.join(" ")+'"'+a(l)+">"+o.content+"</span>":'<span style="'+i.join(";")+'"'+a(l)+">"+o.content+"</span>"}}]),n}()}).call(this,e("_process"))},{_process:1}]},{},[2])(2)}); | ||
"use strict"; | ||
var _typeof2 = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
function _classCallCheck(e, n) { | ||
if (!(e instanceof n)) throw new TypeError("Cannot call a class as a function"); | ||
}var _createClass = function () { | ||
function e(e, n) { | ||
for (var r = 0; r < n.length; r++) { | ||
var t = n[r];t.enumerable = t.enumerable || !1, t.configurable = !0, "value" in t && (t.writable = !0), Object.defineProperty(e, t.key, t); | ||
} | ||
}return function (n, r, t) { | ||
return r && e(n.prototype, r), t && e(n, t), n; | ||
}; | ||
}(), | ||
_typeof = "function" == typeof Symbol && "symbol" == _typeof2(Symbol.iterator) ? function (e) { | ||
return typeof e === "undefined" ? "undefined" : _typeof2(e); | ||
} : function (e) { | ||
return e && "function" == typeof Symbol && e.constructor === Symbol ? "symbol" : typeof e === "undefined" ? "undefined" : _typeof2(e); | ||
};!function (e) { | ||
if ("object" === ("undefined" == typeof exports ? "undefined" : _typeof(exports)) && "undefined" != typeof module) module.exports = e();else if ("function" == typeof define && define.amd) define([], e);else { | ||
var n;n = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof self ? self : this, n.ansiToJson = e(); | ||
} | ||
}(function () { | ||
return function e(n, r, t) { | ||
function o(i, u) { | ||
if (!r[i]) { | ||
if (!n[i]) { | ||
var l = "function" == typeof require && require;if (!u && l) return l(i, !0);if (s) return s(i, !0);var a = new Error("Cannot find module '" + i + "'");throw a.code = "MODULE_NOT_FOUND", a; | ||
}var c = r[i] = { exports: {} };n[i][0].call(c.exports, function (e) { | ||
var r = n[i][1][e];return o(r ? r : e); | ||
}, c, c.exports, e, n, r, t); | ||
}return r[i].exports; | ||
}for (var s = "function" == typeof require && require, i = 0; i < t.length; i++) { | ||
o(t[i]); | ||
}return o; | ||
}({ 1: [function (e, n) { | ||
function r() { | ||
a = !1, i.length ? l = i.concat(l) : c = -1, l.length && t(); | ||
}function t() { | ||
if (!a) { | ||
var e = setTimeout(r);a = !0;for (var n = l.length; n;) { | ||
for (i = l, l = []; ++c < n;) { | ||
i && i[c].run(); | ||
}c = -1, n = l.length; | ||
}i = null, a = !1, clearTimeout(e); | ||
} | ||
}function o(e, n) { | ||
this.fun = e, this.array = n; | ||
}function s() {}var i, | ||
u = n.exports = {}, | ||
l = [], | ||
a = !1, | ||
c = -1;u.nextTick = function (e) { | ||
var n = new Array(arguments.length - 1);if (arguments.length > 1) for (var r = 1; r < arguments.length; r++) { | ||
n[r - 1] = arguments[r]; | ||
}l.push(new o(e, n)), 1 !== l.length || a || setTimeout(t, 0); | ||
}, o.prototype.run = function () { | ||
this.fun.apply(null, this.array); | ||
}, u.title = "browser", u.browser = !0, u.env = {}, u.argv = [], u.version = "", u.versions = {}, u.on = s, u.addListener = s, u.once = s, u.off = s, u.removeListener = s, u.removeAllListeners = s, u.emit = s, u.binding = function () { | ||
throw new Error("process.binding is not supported"); | ||
}, u.cwd = function () { | ||
return "/"; | ||
}, u.chdir = function () { | ||
throw new Error("process.chdir is not supported"); | ||
}, u.umask = function () { | ||
return 0; | ||
}; | ||
}, {}], 2: [function (e, n) { | ||
function r(e) { | ||
return t.ansiToJson(e, { json: !0, remove_empty: !0 }); | ||
}var t = e("anser");n.exports = r; | ||
}, { anser: 3 }], 3: [function (e, n) { | ||
(function () { | ||
var e = [[{ color: "0, 0, 0", "class": "ansi-black" }, { color: "187, 0, 0", "class": "ansi-red" }, { color: "0, 187, 0", "class": "ansi-green" }, { color: "187, 187, 0", "class": "ansi-yellow" }, { color: "0, 0, 187", "class": "ansi-blue" }, { color: "187, 0, 187", "class": "ansi-magenta" }, { color: "0, 187, 187", "class": "ansi-cyan" }, { color: "255,255,255", "class": "ansi-white" }], [{ color: "85, 85, 85", "class": "ansi-bright-black" }, { color: "255, 85, 85", "class": "ansi-bright-red" }, { color: "0, 255, 0", "class": "ansi-bright-green" }, { color: "255, 255, 85", "class": "ansi-bright-yellow" }, { color: "85, 85, 255", "class": "ansi-bright-blue" }, { color: "255, 85, 255", "class": "ansi-bright-magenta" }, { color: "85, 255, 255", "class": "ansi-bright-cyan" }, { color: "255, 255, 255", "class": "ansi-bright-white" }]];n.exports = function () { | ||
function n() { | ||
_classCallCheck(this, n), this.fg = this.bg = this.fg_truecolor = this.bg_truecolor = null, this.bright = 0; | ||
}return _createClass(n, null, [{ key: "escapeForHtml", value: function value(e) { | ||
return new n().escapeForHtml(e); | ||
} }, { key: "linkify", value: function value(e) { | ||
return new n().linkify(e); | ||
} }, { key: "ansiToHtml", value: function value(e, r) { | ||
return new n().ansiToHtml(e, r); | ||
} }, { key: "ansiToJson", value: function value(e, r) { | ||
return new n().ansiToJson(e, r); | ||
} }, { key: "ansiToText", value: function value(e) { | ||
return new n().ansiToText(e); | ||
} }]), _createClass(n, [{ key: "setupPalette", value: function value() { | ||
this.PALETTE_COLORS = [];for (var n = 0; 2 > n; ++n) { | ||
for (var r = 0; 8 > r; ++r) { | ||
this.PALETTE_COLORS.push(e[n][r].color); | ||
} | ||
}for (var t = [0, 95, 135, 175, 215, 255], o = function o(e, n, r) { | ||
return t[e] + ", " + t[n] + ", " + t[r]; | ||
}, s = 0; 6 > s; ++s) { | ||
for (var i = 0; 6 > i; ++i) { | ||
for (var u = 0; 6 > u; ++u) { | ||
this.PALETTE_COLORS.push(o(s, i, u)); | ||
} | ||
} | ||
}for (var l = 8, a = 0; 24 > a; ++a, l += 10) { | ||
this.PALETTE_COLORS.push(o(l, l, l)); | ||
} | ||
} }, { key: "escapeForHtml", value: function value(e) { | ||
return e.replace(/[&<>]/gm, function (e) { | ||
return "&" == e ? "&" : "<" == e ? "<" : ">" == e ? ">" : ""; | ||
}); | ||
} }, { key: "linkify", value: function value(e) { | ||
return e.replace(/(https?:\/\/[^\s]+)/gm, function (e) { | ||
return '<a href="' + e + '">' + e + "</a>"; | ||
}); | ||
} }, { key: "ansiToHtml", value: function value(e, n) { | ||
return this.process(e, n, !0); | ||
} }, { key: "ansiToJson", value: function value(e, n) { | ||
return n = n || {}, n.json = !0, this.process(e, n, !0); | ||
} }, { key: "ansiToText", value: function value(e) { | ||
return this.process(e, {}, !1); | ||
} }, { key: "process", value: function value(e, n, r) { | ||
var t = this, | ||
o = this, | ||
s = e.split(/\033\[/), | ||
i = s.shift(), | ||
u = s.map(function (e) { | ||
return t.processChunk(e, n, r); | ||
});if (n && n.json) { | ||
var l = o.processChunkJson("");return l.content = i, u.unshift(l), n.remove_empty && (u = u.filter(function (e) { | ||
return !e.isEmpty(); | ||
})), u; | ||
}return u.unshift(i), u.join(""); | ||
} }, { key: "processChunkJson", value: function value(n, r, t) { | ||
r = "undefined" == typeof r ? {} : r;var o = r.use_classes = "undefined" != typeof r.use_classes && r.use_classes, | ||
s = r.key = o ? "class" : "color", | ||
i = { content: n, fg: null, bg: null, fg_truecolor: null, bg_truecolor: null, was_processed: !1, isEmpty: function isEmpty() { | ||
return !i.content; | ||
} }, | ||
u = n.match(/^([!\x3c-\x3f]*)([\d;]*)([\x20-\x2c]*[\x40-\x7e])([\s\S]*)/m);if (!u) return i;var l = (i.content = u[4], u[2].split(";"));if ("" !== u[1] || "m" !== u[3]) return i;if (!t) return i;for (var a = this; l.length > 0;) { | ||
var c = l.shift(), | ||
f = parseInt(c);if (isNaN(f) || 0 === f) a.fg = a.bg = null, a.bright = 0;else if (1 === f) a.bright = 1;else if (39 == f) a.fg = null;else if (49 == f) a.bg = null;else if (f >= 30 && 38 > f) a.fg = e[a.bright][f % 10][s];else if (f >= 90 && 98 > f) a.fg = e[1][f % 10][s];else if (f >= 40 && 48 > f) a.bg = e[0][f % 10][s];else if (f >= 100 && 108 > f) a.bg = e[1][f % 10][s];else if (38 === f || 48 === f) { | ||
var g = 38 === f;if (l.length >= 1) { | ||
var p = l.shift();if ("5" === p && l.length >= 1) { | ||
var h = parseInt(l.shift());if (h >= 0 && 255 >= h) if (o) { | ||
var b = h >= 16 ? "ansi-palette-" + h : e[h > 7 ? 1 : 0][h % 8]["class"];g ? a.fg = b : a.bg = b; | ||
} else this.PALETTE_COLORS || a.setupPalette(), g ? a.fg = this.PALETTE_COLORS[h] : a.bg = this.PALETTE_COLORS[h]; | ||
} else if ("2" === p && l.length >= 3) { | ||
var v = parseInt(l.shift()), | ||
y = parseInt(l.shift()), | ||
d = parseInt(l.shift());if (v >= 0 && 255 >= v && y >= 0 && 255 >= y && d >= 0 && 255 >= d) { | ||
var m = v + ", " + y + ", " + d;o ? g ? (a.fg = "ansi-truecolor", a.fg_truecolor = m) : (a.bg = "ansi-truecolor", a.bg_truecolor = m) : g ? a.fg = m : a.bg = m; | ||
} | ||
} | ||
} | ||
} | ||
}if (null === a.fg && null === a.bg) return i;return i.fg = a.fg, i.bg = a.bg, i.fg_truecolor = a.fg_truecolor, i.bg_truecolor = a.bg_truecolor, i.was_processed = !0, i; | ||
} }, { key: "processChunk", value: function value(e, n, r) { | ||
var t = this;n = n || {};var o = this.processChunkJson(e, n, r);if (n.json) return o;if (o.isEmpty()) return "";if (!o.was_processed) return o.content;var s = n.use_classes, | ||
i = [], | ||
u = [], | ||
l = {}, | ||
a = function a(e) { | ||
var n = [], | ||
r = void 0;for (r in e) { | ||
e.hasOwnProperty(r) && n.push("data-" + r + '="' + t.escapeForHtml(e[r]) + '"'); | ||
}return n.length > 0 ? " " + n.join(" ") : ""; | ||
};return o.fg && (s ? (u.push(o.fg + "-fg"), null !== o.fg_truecolor && (l["ansi-truecolor-fg"] = o.fg_truecolor, o.fg_truecolor = null)) : i.push("color:rgb(" + o.fg + ")")), o.bg && (s ? (u.push(o.bg + "-bg"), null !== o.bg_truecolor && (l["ansi-truecolor-bg"] = o.bg_truecolor, o.bg_truecolor = null)) : i.push("background-color:rgb(" + o.bg + ")")), s ? '<span class="' + u.join(" ") + '"' + a(l) + ">" + o.content + "</span>" : '<span style="' + i.join(";") + '"' + a(l) + ">" + o.content + "</span>"; | ||
} }]), n; | ||
}(); | ||
}).call(this, e("_process")); | ||
}, { _process: 1 }] }, {}, [2])(2); | ||
}); |
"use strict"; | ||
const Anser = require("anser"); | ||
var Anser = require("anser"); | ||
@@ -14,9 +14,9 @@ /** | ||
*/ | ||
function ansiToJson (input) { | ||
function ansiToJson(input) { | ||
return Anser.ansiToJson(input, { | ||
json: true | ||
, remove_empty: true | ||
json: true, | ||
remove_empty: true | ||
}); | ||
} | ||
module.exports = ansiToJson; | ||
module.exports = ansiToJson; |
@@ -14,3 +14,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"main": "dist/ansi-to-json.js", | ||
@@ -43,2 +43,3 @@ "scripts": { | ||
"menu/", | ||
"scripts/", | ||
"cli.js", | ||
@@ -45,0 +46,0 @@ "index.js" |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
13474
187
4
2
0
1