(rawName: string)
| 4 | * Converts valid file names to valid javascript symbols and does best effort to make them readable. Example: ds-token.test becomes DsTokenTest |
| 5 | */ |
| 6 | export function normalizeName(rawName: string): string { |
| 7 | const transformations: ((s: string) => string)[] = [ |
| 8 | (s) => s.replace(/\s+/g, '-'), // spaces to - so later we can automatically convert them |
| 9 | (s) => s.replace(/\./g, '-'), // replace "." |
| 10 | (s) => s.replace(/-[a-z]/g, (match) => match.substr(-1).toUpperCase()), // delete '-' and capitalize the letter after them |
| 11 | (s) => s.replace(/-/g, ''), // delete any '-' left |
| 12 | (s) => s.replace(/^\d+/, ''), // removes leading digits |
| 13 | (s) => upperFirst(s), |
| 14 | ] |
| 15 | |
| 16 | const finalName = transformations.reduce((s, t) => t(s), rawName) |
| 17 | |
| 18 | if (finalName === '') { |
| 19 | throw new Error(`Can't guess class name, please rename file: ${rawName}`) |
| 20 | } |
| 21 | |
| 22 | return finalName |
| 23 | } |
no outgoing calls
no test coverage detected
searching dependent graphs…