Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a simple function to add color into an existing string. Has a t…

…ry/catch block to trap invalid regex.
  • Loading branch information...
commit 932d42116b604ce7bca19f1cf8f62aa6c1b1f0b1 1 parent 56dde40
@ollieparsley ollieparsley authored
Showing with 12 additions and 1 deletion.
  1. +12 −1 lib/ansi-color.js
View
13 lib/ansi-color.js
@@ -42,10 +42,21 @@ function logMessage(message,color) {
console.log(setColor(message,color));
}
+function replace(full_text, search_regex, color) {
+ try {
+ var regex = new RegExp('(' + search_regex + ')', 'ig');
+ var new_text = full_text.replace(regex, setColor('$1', color));
+ return new_text;
+ } catch (e) {
+ return full_text;
+ }
+}
+
if (typeof exports !== "undefined") {
exports.log = logMessage;
exports.set = setColor;
+ exports.replace = replace;
} else if (typeof define !== "undefined") {
define([], function() { return { set: setColor, log: logMessage }; });
}
-}());
+}());
Please sign in to comment.
Something went wrong with that request. Please try again.