Socket
Socket
Sign inDemoInstall

anser

Package Overview
Dependencies
0
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.4.10 to 2.0.0

7

lib/index.d.ts
// Type definitions for Anser
// Project: https://github.com/IonicaBizau/anser
type DecorationName = 'bold' | 'dim' | 'italic' | 'underline' | 'blink' | 'reverse' | 'hidden' | 'strikethrough';
export interface AnserJsonEntry {

@@ -17,3 +19,6 @@ /** The text. */

clearLine: boolean;
decoration: null | 'bold' | 'dim' | 'italic' | 'underline' | 'blink' | 'reverse' | 'hidden' | 'strikethrough';
/** The decoration last declared before the text. */
decoration: null | DecorationName;
/** All decorations that apply to the text. */
decorations: Array<DecorationName>;
/** `true` if the colors were processed, `false` otherwise. */

@@ -20,0 +25,0 @@ was_processed: boolean;

114

lib/index.js

@@ -361,4 +361,6 @@ "use strict";

bg_truecolor: null,
isInverted: false,
clearLine: options.clearLine,
decoration: null,
decorations: [],
was_processed: false,

@@ -402,3 +404,3 @@ isEmpty: function isEmpty() {

self.decoration = null;
self.decorations = self.decorations || [];

@@ -410,21 +412,22 @@ while (nums.length > 0) {

if (isNaN(num) || num === 0) {
self.fg = self.bg = self.decoration = null;
self.fg = self.bg = null;
self.decorations = [];
} else if (num === 1) {
self.decoration = "bold";
self.decorations.push("bold");
} else if (num === 2) {
self.decoration = "dim";
self.decorations.push("dim");
// Enable code 2 to get string
} else if (num == 3) {
self.decoration = "italic";
self.decorations.push("italic");
} else if (num == 4) {
self.decoration = "underline";
self.decorations.push("underline");
} else if (num == 5) {
self.decoration = "blink";
self.decorations.push("blink");
} else if (num === 7) {
self.decoration = "reverse";
self.decorations.push("reverse");
} else if (num === 8) {
self.decoration = "hidden";
self.decorations.push("hidden");
// Enable code 9 to get strikethrough
} else if (num === 9) {
self.decoration = "strikethrough";
self.decorations.push("strikethrough");
} else if (num == 39) {

@@ -501,3 +504,3 @@ self.fg = null;

if (self.fg === null && self.bg === null && self.decoration === null) {
if (self.fg === null && self.bg === null && self.decorations.length === 0) {
return result;

@@ -513,3 +516,4 @@ } else {

result.bg_truecolor = self.bg_truecolor;
result.decoration = self.decoration;
result.decorations = self.decorations;
result.decoration = self.decorations.slice(-1).pop() || null;
result.was_processed = true;

@@ -542,6 +546,28 @@

var self = this;
options = options || {};
var jsonChunk = this.processChunkJson(text, options, markup);
var use_classes = options.use_classes;
// "reverse" decoration reverses foreground and background colors
jsonChunk.decorations = jsonChunk.decorations.filter(function (decoration) {
if (decoration === "reverse") {
// when reversing, missing colors are defaulted to black (bg) and white (fg)
if (!jsonChunk.fg) {
jsonChunk.fg = ANSI_COLORS[0][7][use_classes ? "class" : "color"];
}
if (!jsonChunk.bg) {
jsonChunk.bg = ANSI_COLORS[0][0][use_classes ? "class" : "color"];
}
var tmpFg = jsonChunk.fg;
jsonChunk.fg = jsonChunk.bg;
jsonChunk.bg = tmpFg;
var tmpFgTrue = jsonChunk.fg_truecolor;
jsonChunk.fg_truecolor = jsonChunk.bg_truecolor;
jsonChunk.bg_truecolor = tmpFgTrue;
jsonChunk.isInverted = true;
return false;
}
return true;
});
if (options.json) {

@@ -557,7 +583,7 @@ return jsonChunk;

var use_classes = options.use_classes;
var colors = [];
var decorations = [];
var textDecorations = [];
var data = {};
var styles = [];
var classes = [];
var data = {};
var render_data = function render_data(data) {

@@ -574,5 +600,9 @@ var fragments = [];

if (jsonChunk.isInverted) {
data["ansi-is-inverted"] = "true";
}
if (jsonChunk.fg) {
if (use_classes) {
classes.push(jsonChunk.fg + "-fg");
colors.push(jsonChunk.fg + "-fg");
if (jsonChunk.fg_truecolor !== null) {

@@ -583,3 +613,3 @@ data["ansi-truecolor-fg"] = jsonChunk.fg_truecolor;

} else {
styles.push("color:rgb(" + jsonChunk.fg + ")");
colors.push("color:rgb(" + jsonChunk.fg + ")");
}

@@ -590,3 +620,3 @@ }

if (use_classes) {
classes.push(jsonChunk.bg + "-bg");
colors.push(jsonChunk.bg + "-bg");
if (jsonChunk.bg_truecolor !== null) {

@@ -597,31 +627,37 @@ data["ansi-truecolor-bg"] = jsonChunk.bg_truecolor;

} else {
styles.push("background-color:rgb(" + jsonChunk.bg + ")");
colors.push("background-color:rgb(" + jsonChunk.bg + ")");
}
}
if (jsonChunk.decoration) {
jsonChunk.decorations.forEach(function (decoration) {
// use classes
if (use_classes) {
classes.push("ansi-" + jsonChunk.decoration);
} else if (jsonChunk.decoration === "bold") {
styles.push("font-weight:bold");
} else if (jsonChunk.decoration === "dim") {
styles.push("opacity:0.5");
} else if (jsonChunk.decoration === "italic") {
styles.push("font-style:italic");
// underline and blink are treated bellow
} else if (jsonChunk.decoration === "reverse") {
styles.push("filter:invert(100%)");
} else if (jsonChunk.decoration === "hidden") {
styles.push("visibility:hidden");
} else if (jsonChunk.decoration === "strikethrough") {
styles.push("text-decoration:line-through");
decorations.push("ansi-" + decoration);
return;
}
// use styles
if (decoration === "bold") {
decorations.push("font-weight:bold");
} else if (decoration === "dim") {
decorations.push("opacity:0.5");
} else if (decoration === "italic") {
decorations.push("font-style:italic");
} else if (decoration === "hidden") {
decorations.push("visibility:hidden");
} else if (decoration === "strikethrough") {
textDecorations.push("line-through");
} else {
styles.push("text-decoration:" + jsonChunk.decoration);
// underline and blink are treated here
textDecorations.push(decoration);
}
});
if (textDecorations.length) {
decorations.push("text-decoration:" + textDecorations.join(" "));
}
if (use_classes) {
return "<span class=\"" + classes.join(" ") + "\"" + render_data(data) + ">" + jsonChunk.content + "</span>";
return "<span class=\"" + colors.concat(decorations).join(" ") + "\"" + render_data(data) + ">" + jsonChunk.content + "</span>";
} else {
return "<span style=\"" + styles.join(";") + "\"" + render_data(data) + ">" + jsonChunk.content + "</span>";
return "<span style=\"" + colors.concat(decorations).join(";") + "\"" + render_data(data) + ">" + jsonChunk.content + "</span>";
}

@@ -628,0 +664,0 @@ }

{
"name": "anser",
"version": "1.4.10",
"version": "2.0.0",
"description": "A low level parser for ANSI sequences.",

@@ -5,0 +5,0 @@ "keywords": [

@@ -421,6 +421,7 @@ <!-- Please do not edit this file. Edit the `blah` field in the `package.json` instead. If in doubt, open an issue. -->

- `react-native`
- `react-native-windows`
- `ansi-to-react`
- `mesh-devtool`
- `@next/react-dev-overlay`
- `nuclide-commons-ui`
- `@next/react-dev-overlay`
- `transformime`

@@ -430,2 +431,5 @@ - `@viankakrisna/react-dev-utils`

- `redux-devtools-trace-monitor`
- `ansi-to-json`
- `@axio/react-dev-utils`
- `react-error-overlay-dangerous`
- `timer-react-dev-utils`

@@ -439,6 +443,3 @@ - `react-dev-utils-extra`

- `react-error-overlay-canary`
- `@axio/react-dev-utils`
- `react-error-overlay-dangerous`
- `@classflow/react-dev-utils`
- `ansi-to-json`
- `nuclide`

@@ -448,4 +449,7 @@ - `react-native-okhttp-fork`

- `ipynb2html`
- `ipynb2html-fix`
- `@theia/console`
- `react-native-macos`
- `webpack-isomorphic-dev-middleware`
- `@theia/console`
- `@ehyland-org/react-error-overlay`
- `stack-frame-overlay`

@@ -459,3 +463,2 @@ - `cycle-dev-utils`

- `zc-react-dev-utils`
- `@ehyland-org/react-error-overlay`
- `react-dev-utils-custom-hmr`

@@ -468,3 +471,2 @@ - `ansi-to-react-with-classes`

- `@unforgiven/react-native`
- `react-ansi`
- `@digibear/socket-bridge`

@@ -475,7 +477,11 @@ - `ada-pack`

- `@prague-digi/react-error-overlay`
- `kunai`
- `@apardellass/react-native-audio-stream`
- `react-native-tvos`
- `react-native-plugpag-wrapper`
- `@codewars/jest-reporter`
- `react-native-tvos`
- `@proteria/react-scripts`
- `kunai`
- `@office-iss/react-native-win32`
- `react-ansi`
- `react-native-pulsator-native`

@@ -482,0 +488,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc