(str: string)
| 236 | |
| 237 | // Sanitizes and formats a string to make an appropriate identifier in Go |
| 238 | function format(str: string) { |
| 239 | str = formatNumber(str) |
| 240 | |
| 241 | const sanitized = toProperCase(str).replace(/[^a-z0-9]/gi, '') |
| 242 | if (!sanitized) { |
| 243 | return 'NAMING_FAILED' |
| 244 | } |
| 245 | |
| 246 | // After sanitizing the remaining characters can start with a number. |
| 247 | // Run the sanitized string again trough formatNumber to make sure the identifier is Num[0-9] or Zero_... instead of 1. |
| 248 | return formatNumber(sanitized) |
| 249 | } |
| 250 | |
| 251 | // Adds a prefix to a number to make an appropriate identifier in Go |
| 252 | function formatNumber(str: string) { |
no test coverage detected