UNPKG

885 BJavaScriptView Raw
1'use strict';
2
3/*
4 * stringUtil.js deals with string operations
5 *
6 */
7
8// Get rid of color ANSI codes
9module.exports.getRidOfColors = function (str) {
10 return str.replace(/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '');
11};
12
13// Get rid of any quotation marks that might interfere with parsing
14module.exports.getRidOfQuotationMarks = function (str) {
15 return str.replace(/['"]+/g, '');
16};
17
18// Truncate
19module.exports.truncate = function (str, maxWidth = 50, truncateMarker = true) {
20 if (truncateMarker) {
21 str = str.length > maxWidth ? str.substring(0, maxWidth) + '...' : str;
22 } else {
23 str = str.length > maxWidth ? str.substring(0, maxWidth) : str;
24 }
25 return str;
26};
27
28// Clean tag name
29module.exports.cleanTagName = function (str) {
30 if (str.includes('semantic')) {
31 let moduleName = str.split('@')[0];
32 return moduleName;
33 }
34 return str;
35};
\No newline at end of file