MCPcopy Create free account
hub / github.com/wevm/viem / getUniqueImportName

Function getUniqueImportName

scripts/generateTokenlist.ts:408–419  ·  view source on GitHub ↗
(
  token: Pick<TokenDefinition, 'name' | 'symbol'>,
  usedImportNames: Set<string>,
)

Source from the content-addressed store, hash-verified

406}
407
408function 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
421function toIdentifier(value: string) {
422 const identifier = value.replace(/[^a-zA-Z0-9]+/g, '').toLowerCase()

Callers 1

getTokenDefinitionsFunction · 0.85

Calls 1

toIdentifierFunction · 0.85

Tested by

no test coverage detected