Skip to content

Commit

Permalink
Update ansi-color.js
Browse files Browse the repository at this point in the history
Fix for `Legacy octal escape is not permitted in strict mode`

Reference : open-telemetry/opentelemetry-js#3759 (comment)
  • Loading branch information
anubhavchaturvedi authored May 7, 2024
1 parent ee861d0 commit b19f2cc
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/ansi-color.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ var ANSI_CODES = {
"white_bg": 47
};

function setColor(str,color) {
if(!color) return str;
function setColor(str, color) {
if (!color) return str;
var color_attrs = color.split("+");
var ansi_str = "";
for(var i=0, attr; attr = color_attrs[i]; i++) {
ansi_str += "\033[" + ANSI_CODES[attr] + "m";
for (var i = 0, attr; attr = color_attrs[i]; i++) {
ansi_str += "\x1b[" + ANSI_CODES[attr] + "m"; // \x1b is the hexadecimal representation for ESC (0o33 or \033 in octal)
}
ansi_str += str + "\033[" + ANSI_CODES["off"] + "m";
ansi_str += str + "\x1b[" + ANSI_CODES["off"] + "m";
return ansi_str;
}

Expand All @@ -59,4 +59,4 @@ if (typeof exports !== "undefined") {
} else if (typeof define !== "undefined") {
define([], function() { return { set: setColor, log: logMessage }; });
}
}());
}());

0 comments on commit b19f2cc

Please sign in to comment.