Skip to content

Commit

Permalink
fix(string-length): replace tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Mollweide committed Apr 22, 2018
1 parent 9337f25 commit 2b43389
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/stripTerminalString/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
/**
* @param {string} value - value string
* @returns {string} - retruns the parsed value (\b, \t)
**/
function stripTerminalString(value) {
const stripBackslashes = value => {
const result = value.split('\b');
if (result.length < 2) {
return value;
}
return `${result[0]}${result[result.length - 1]}`;
};
const stripTabs = value => {
const result = value.split('\t');
if (result.length < 2) {
return value;
}
return result.join(' ');
};

/**
* @param {string} value - value string
* @returns {string} - retruns the parsed value (\b, \t)
**/
function stripTerminalString(value) {
return stripBackslashes(stripTabs(value));
}

module.exports = stripTerminalString;
22 changes: 22 additions & 0 deletions src/stripTerminalString/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,26 @@ describe('stripTerminalString', () => {
)
);
});
it('tabs', () => {
expect(
JSON.stringify(
{
text: stripTerminalString(
'\u001b[31m \t\t10% building modules 2/2 modules 0 active(node:11160) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead\u001b[39m'
),
},
null,
2
)
).toEqual(
JSON.stringify(
{
text:
'\u001b[31m 10% building modules 2/2 modules 0 active(node:11160) DeprecationWarning: Tapable.plugin is deprecated. Use new API on `.hooks` instead\u001b[39m',
},
null,
2
)
);
});
});

0 comments on commit 2b43389

Please sign in to comment.