• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

luttje / glua-api-snippets / 14570100579

21 Apr 2025 08:17AM UTC coverage: 79.894% (+0.5%) from 79.358%
14570100579

Pull #83

github

web-flow
Merge bee16cd7e into 55a61523b
Pull Request #83: Fixing issues in backlog

335 of 418 branches covered (80.14%)

Branch coverage included in aggregate %.

103 of 107 new or added lines in 3 files covered. (96.26%)

3 existing lines in 1 file now uncovered.

1779 of 2228 relevant lines covered (79.85%)

441.95 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.6
/src/utils/string.ts
1
/**
1✔
2
 * Converts a string to lowerCamelCase
1✔
3
 *
1✔
4
 * @param str The string to convert
1✔
5
 * @returns The converted string
1✔
6
 */
1✔
7
export function toLowerCamelCase(str: string) {
1✔
8
  str = str.replace(/[_-]/g, ' ');
12✔
9
  return str.replace(/(?:^\w|\b\w)/g, (letter, index) => {
12✔
10
    return index === 0 ? letter.toLowerCase() : letter.toUpperCase();
28✔
11
  }).replace(/\s+/g, '');
12✔
12
}
12✔
13

1✔
14
/**
1✔
15
 * Replaces all newlines in a string with spaces
1✔
16
 */
1✔
17
export function removeNewlines(text: string) {
1✔
18
  return text.replace(/\r?\n/g, ' ');
5✔
19
}
5✔
20

1✔
21
/**
1✔
22
 * Puts a comment before each line in a string
1✔
23
 */
1✔
24
function putCommentBeforeEachLine(text: string, skipLineOne: boolean = true) {
87✔
25
  return text.split(/\r?\n/g).map((line, index) => {
87✔
26
    if (index === 0 && skipLineOne)
164✔
27
      return line;
164✔
28

91✔
29
    line = line.trimEnd();
91✔
30
    let space = line.length > 0 ? ' ' : '';
164✔
31
    return `---${space}${line}`;
164✔
32
  }).join('\n');
87✔
33
}
87✔
34

1✔
35
/**
1✔
36
 * Puts every following line in a long comment. We do this so any markdown
1✔
37
 * inside the comment doesn't break. Like markdown tables only work in
1✔
38
 * long comments.
1✔
39
 */
1✔
40
export function wrapInComment(text: string, skipLineOne: boolean = true) {
1✔
41
  // Trim any leading and trailing line breaks, or lines with only white spaces.
89✔
42
  text = text.replace(/^\s*\r?\n|\r?\n\s*$/g, '');
89✔
43

89✔
44
  // Remove duplicate consequitive new lines.
89✔
45
  while (text.match(/\r?\n\r?\n\r?\n/g)) {
89✔
46
    text = text.replace(/\r?\n\r?\n\r?\n/g, "\n\n");
5✔
47
  }
5✔
48

89✔
49
  text = unindentText(text);
89✔
50

89✔
51
  // If the text contains no markdown tables, we use the old method
89✔
52
  // of putting a comment before each line.
89✔
53
  if (!text.match(/^\s*\|.*\|\s*\n^\s*\|(?:\s*[:\-]+[-| :]*).*$/gm)) {
89✔
54
    return putCommentBeforeEachLine(text, skipLineOne);
87✔
55
  }
87✔
56

2✔
57
  const lines = text.split(/\r?\n/g);
2✔
58
  let output = '';
2✔
59
  let i = 0;
2✔
60

2✔
61
  if (skipLineOne) {
9✔
62
    if (lines.length <= 1) {
1!
NEW
63
      return text;
×
NEW
64
    }
×
65

1✔
66
    output = `${lines[0]}\n--[[\n`;
1✔
67
    i = 1;
1✔
68
  } else {
1✔
69
    output = '--[[\n';
1✔
70
  }
1✔
71

2✔
72
  for (; i < lines.length; i++) {
9✔
73
    output += `${lines[i]}\n`;
11✔
74
  }
11✔
75

2✔
76
  output += '--]]';
2✔
77

2✔
78
  return output;
2✔
79
}
2✔
80

1✔
81
/**
1✔
82
 * Makes a string safe for use as a file name
1✔
83
 *
1✔
84
 * @param str The string to make safe
1✔
85
 * @param replacement The string to replace unsafe characters with
1✔
86
 * @returns The safe string
1✔
87
 */
1✔
88
export function safeFileName(str: string, replacement: string = '_') {
1✔
89
  return str.replace(/[^a-z0-9_\-\. ]/gi, replacement);
27✔
90
}
27✔
91

1✔
92
/**
1✔
93
 * Escapes all single quotes in a string
1✔
94
 *
1✔
95
 * @param str The string to escape
1✔
96
 * @returns The escaped string
1✔
97
 */
1✔
98
export function escapeSingleQuotes(str: string) {
1✔
99
  return str.replace(/'/g, '\\\'');
×
100
}
×
101

1✔
102
/**
1✔
103
 * Indents all lines in a string by a given amount
1✔
104
 *
1✔
105
 * @param text The text to indent
1✔
106
 * @param indent The amount of spaces to indent by
1✔
107
 * @returns The indented text
1✔
108
 */
1✔
109
export function indentText(text: string, indent: number) {
1✔
110
  return text.split('\n').map(line => ' '.repeat(indent) + line).join('\n');
4✔
111
}
4✔
112

1✔
113
/**
1✔
114
 * Unindents all lines in the text using the given indent amount or
1✔
115
 * by the first line's indent amount.
1✔
116
 * @param text The text to unindent
1✔
117
 * @param indent The amount of spaces to unindent by
1✔
118
 * @returns The unindented text
1✔
119
 */
1✔
120
export function unindentText(text: string, indent: number = 0) {
1✔
121
  const lines = text.split('\n');
95✔
122

95✔
123
  if (lines.length === 0)
95✔
124
    return text;
95!
125

95✔
126
  const firstLineIndent = lines[0].search(/\S/);
95✔
127
  const unindentAmount = indent > 0 ? indent : firstLineIndent;
95!
128

95✔
129
  return lines.map(line => line.slice(unindentAmount)).join('\n');
95✔
130
}
95✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc