pdn
Version:
POSIX-friendly Data Notation
24 lines (20 loc) • 472 B
JavaScript
function* NameGen(key = '') {
if (!key.length) key = 'sym';
const counters = {};
while (true) {
yield `${key}_${counters[key]
? (counters[key] = counters[key] + 1)
: (counters[key] = 1)}`;
}
}
function GenSym() {
const keys = {};
return function NameFactory(key) {
let iter = keys[key] = keys[key] || NameGen(key);
return iter.next().value;
};
}
module.exports = {
GenSym
};
;