UNPKG

@nestjs/core

Version:

Nest - modern, fast, powerful node.js web framework (@core)

21 lines (20 loc) 575 B
export class DeterministicUuidRegistry { static registry = new Map(); static get(str, inc = 0) { const id = inc ? this.hashCode(`${str}_${inc}`) : this.hashCode(str); if (this.registry.has(id)) { return this.get(str, inc + 1); } this.registry.set(id, true); return id; } static clear() { this.registry.clear(); } static hashCode(s) { let h = 0; for (let i = 0; i < s.length; i++) h = (Math.imul(31, h) + s.charCodeAt(i)) | 0; return h.toString(); } }