push
github
3252 of 3846 branches covered (84.56%)
25183 of 31493 relevant lines covered (79.96%)
1188.51 hits per line
1 |
import { slugify } from 'transliteration'; |
2✔ |
2 |
|
2✔ |
3 |
export function convertNameToValidCharacter(name: string, maxLength = 10): string { |
|
4 |
let cleanedName = slugify(name, { allowedChars: 'a-zA-Z0-9_', separator: '_', lowercase: false }); |
4,777✔ |
5 |
|
4,777✔ |
6 |
if (cleanedName === '' || /^_+$/.test(cleanedName)) { |
|
7 |
return 'unnamed'; |
× |
8 |
} |
× |
9 |
|
4,777✔ |
10 |
if (!/^[a-z]/i.test(cleanedName)) {
|
|
11 |
cleanedName = 't' + cleanedName;
|
× |
12 |
} |
× |
13 |
|
4,777✔ |
14 |
cleanedName = cleanedName.substring(0, maxLength);
|
4,777✔ |
15 |
|
4,777✔ |
16 |
return cleanedName;
|
4,777✔ |
17 |
} |
4,777✔ |