* Generates a unique ID with a specific prefix. * @param prefix Prefix to add to the ID. * @param randomize Add a randomized infix string.
(prefix: string, randomize: boolean = false)
| 29 | * @param randomize Add a randomized infix string. |
| 30 | */ |
| 31 | getId(prefix: string, randomize: boolean = false): string { |
| 32 | // Omit the app ID if it's the default `ng`. Since the vast majority of pages have one |
| 33 | // Angular app on them, we can reduce the amount of breakages by not adding it. |
| 34 | if (this._appId !== 'ng') { |
| 35 | prefix += this._appId; |
| 36 | } |
| 37 | |
| 38 | let count = counters.get(prefix); |
| 39 | |
| 40 | if (count === undefined) { |
| 41 | count = 0; |
| 42 | } else { |
| 43 | count++; |
| 44 | } |
| 45 | |
| 46 | counters.set(prefix, count); |
| 47 | return `${prefix}${randomize ? _IdGenerator._infix + '-' : ''}${count}`; |
| 48 | } |
| 49 | } |
no test coverage detected