export class NameGenerator { private base64Chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789" ; public getName ( index ) { const RESERVED_KEYWORDS = [ "do" , "if" , "in" , "for" , "int" , "let" , "new" , "try" , "var" ] ; let name ; while ( true ) { name = this . generateName ( index ++ ) ; if ( RESERVED_KEYWORDS . indexOf ( name ) > 0 ) { continue ; } else { return name ; } } } private generateName ( index ) { let id = index ; let name = this . base64Chars [ id % 54 ] ; id = Math . floor ( id / 54 ) ; while ( id > 0 ) { name += this . base64Chars [ id % 64 ] ; id = Math . floor ( id / 64 ) ; } return name ; } }