( token: Pick<TokenDefinition, 'name' | 'symbol'>, usedImportNames: Set<string>, )
| 406 | } |
| 407 | |
| 408 | function getUniqueImportName( |
| 409 | token: Pick<TokenDefinition, 'name' | 'symbol'>, |
| 410 | usedImportNames: Set<string>, |
| 411 | ) { |
| 412 | const base = toIdentifier(token.symbol) |
| 413 | let importName = base |
| 414 | if (usedImportNames.has(importName)) importName = toIdentifier(token.name) |
| 415 | let index = 2 |
| 416 | while (usedImportNames.has(importName)) importName = `${base}${index++}` |
| 417 | usedImportNames.add(importName) |
| 418 | return importName |
| 419 | } |
| 420 | |
| 421 | function toIdentifier(value: string) { |
| 422 | const identifier = value.replace(/[^a-zA-Z0-9]+/g, '').toLowerCase() |
no test coverage detected