module const MAX_SALTS = 10000 ; const MAX_ENTITY_PER_GENERATOR = Math . floor ( Number . MAX_SAFE_INTEGER / MAX_SALTS ) - 1 ; let currentSalt = 0 ; class export class UIDGenerator { constructor class param { Number } salt salt : number ; uidCounter : number ; constructor ( salt = 0 ) { property this . salt = salt ; property this . uidCounter = 0 ; } return { Number } next ( ) { let nextUid = this . salt + this . uidCounter * MAX_SALTS ; if ( ++ this . uidCounter >= MAX_ENTITY_PER_GENERATOR ) { this . uidCounter = 0 ; } return nextUid ; } } property export const DefaultUIDGenerator = new UIDGenerator ( currentSalt ++ ) ; param { String } entityId param { String } salt return { Boolean } export const isSaltedBy = ( entityId , salt ) : boolean => entityId % MAX_SALTS === salt ; method return { Number } export const nextSalt = ( ) : number => { let salt = currentSalt ; if ( ++ currentSalt > MAX_SALTS - 1 ) { currentSalt = 1 ; } return salt ; } ; method return { UIDGenerator } export const nextGenerator = ( ) : UIDGenerator => new UIDGenerator ( nextSalt ( ) ) ;