const usedIds = new Set < string > ( ) ; const makeId = ( idBase , iteration ) => iteration <= 1 ? idBase : idBase + iteration . toString ( ) ; const isUniqueId = ( idBase , iteration ) => { const newID = makeId ( idBase , iteration ) ; return ! usedIds . has ( newID ) ; } ; export const createId = ( proposedId ) => { if ( proposedId === undefined ) { proposedId = 'undefined' ; } let tries = 0 ; while ( ! isUniqueId ( proposedId , tries ) ) { tries ++ ; } const newID = makeId ( proposedId , tries ) ; usedIds . add ( newID ) ; return newID ; } ; export const removeId = ( id ) => usedIds . delete ( id ) ; export const clearAllIds = ( ) => usedIds . clear ( ) ;