Files
medusa-store/packages/medusa-test-utils/src/id-map.ts
2024-09-30 09:04:03 +02:00

20 lines
330 B
TypeScript

import randomize from "randomatic"
class IdMap {
ids = {}
getId(key, prefix = "", length = 10) {
if (this.ids[key]) {
return this.ids[key]
}
const id = `${prefix && prefix + "_"}${randomize("Aa0", length)}`
this.ids[key] = id
return id
}
}
const instance = new IdMap()
export default instance