Permalink
Browse files

trim - function for removing ANSI formatting from string

  • Loading branch information...
1 parent a53b96e commit e824f4efd6e5b936a0814f7d4d0c74508320a238 @medikoo committed Jul 22, 2011
Showing with 16 additions and 0 deletions.
  1. +9 −0 lib/trim.js
  2. +7 −0 test/trim.js
View
9 lib/trim.js
@@ -0,0 +1,9 @@
+// Trim formatting from string
+
+'use strict';
+
+var r = new RegExp('\x1b\\[\\d{1,2}m', 'g');
+
+module.exports = function (str) {
+ return str.replace(r, '');
+};
View
7 test/trim.js
@@ -0,0 +1,7 @@
+'use strict';
+
+var clc = require('../lib');
+
+module.exports = function (t, a) {
+ a(t(clc.red('raz') + 'dwa' + clc.bold('trzy')), 'razdwatrzy');
+};

0 comments on commit e824f4e

Please sign in to comment.