@specs-feup/lara
Version:
A js port of the popular framework for building source-to-source compilers
20 lines (14 loc) • 409 B
text/typescript
export class IdGeneratorClass {
idCounter = new Map<string, number>();
next(key = "") {
const currentId = this.idCounter.get(key);
if (currentId !== undefined) {
this.idCounter.set(key, currentId + 1);
} else {
this.idCounter.set(key, 0);
}
return `${key}${this.idCounter.get(key) ?? ""}`;
}
}
const IdGenerator = new IdGeneratorClass();
export default IdGenerator;