Skip to content

Commit 9cdcf3a

Browse files
committed
Add test for ansi-trim module
1 parent 8c5ca2f commit 9cdcf3a

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

lib/utils/ansi-trim.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
function ansiTrim (str) {
2-
var r = new RegExp('\x1b(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|' +
3-
'\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)', 'g')
4-
return str.replace(r, '')
5-
}
6-
7-
module.exports = ansiTrim
1+
const r = new RegExp('\x1b(?:\\[(?:\\d+[ABCDEFGJKSTm]|\\d+;\\d+[Hfm]|' +
2+
'\\d+;\\d+;\\d+m|6n|s|u|\\?25[lh])|\\w)', 'g')
3+
module.exports = str => str.replace(r, '')

test/lib/utils/ansi-trim.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const t = require('tap')
2+
const ansiTrim = require('../../../lib/utils/ansi-trim.js')
3+
const chalk = require('chalk')
4+
t.equal(ansiTrim('foo'), 'foo', 'does nothing if no ansis')
5+
t.equal(ansiTrim(chalk.red('foo')), 'foo', 'strips out ansis')

0 commit comments

Comments
 (0)