push
github
3278 of 3875 branches covered (84.59%)
25154 of 31466 relevant lines covered (79.94%)
1188.35 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,749✔ |
5 |
|
4,749✔ |
6 |
if (cleanedName === '' || /^_+$/.test(cleanedName)) { |
|
7 |
return 'unnamed'; |
× |
8 |
} |
× |
9 |
|
4,749✔ |
10 |
if (!/^[a-z]/i.test(cleanedName)) {
|
|
11 |
cleanedName = 't' + cleanedName;
|
× |
12 |
} |
× |
13 |
|
4,749✔ |
14 |
cleanedName = cleanedName.substring(0, maxLength);
|
4,749✔ |
15 |
|
4,749✔ |
16 |
return cleanedName;
|
4,749✔ |
17 |
} |
4,749✔ |