UNPKG

@appshuttle.io/turing

Version:
27 lines (25 loc) 842 B
const crypto = require('crypto') class IDManagement { constructor(){ if(! IDManagement.instance){ /* ID PRODUCER */ this.ids = {} this.getIDForSceneOrControllerWithID = function(itemID) { if (!this.ids[itemID]) { var firstBlock = crypto.randomBytes(2).toString('hex').slice(0,3) var secondBlock = crypto.randomBytes(1).toString('hex') var thirdBlock = crypto.randomBytes(2).toString('hex').slice(0,3) this.ids[itemID] = firstBlock + '-' + secondBlock + '-' + thirdBlock } return this.ids[itemID] } IDManagement.instance = this } return IDManagement.instance } } const instance = new IDManagement() Object.freeze(instance) module.exports = instance