diff --git a/src/stripTerminalString/index.js b/src/stripTerminalString/index.js index 2c83eec..174d5da 100644 --- a/src/stripTerminalString/index.js +++ b/src/stripTerminalString/index.js @@ -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; diff --git a/src/stripTerminalString/index.spec.js b/src/stripTerminalString/index.spec.js index a323325..82a94dd 100644 --- a/src/stripTerminalString/index.spec.js +++ b/src/stripTerminalString/index.spec.js @@ -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 + ) + ); + }); });