import id from 'nanoid' ; let _generate = id ; export function setIdGenerator ( generator ) { _generate = generator as any ; } export function generate ( size ? ) { return _generate ( size ) ; } let me ; if ( typeof global !== 'undefined' && global [ 'window' ] ) { me = global [ 'window' ] ; } else if ( typeof global !== 'undefined' && global [ 'self' ] ) { me = global [ 'self' ] ; } if ( me && typeof _generate !== 'function' ) { const crypto = me . crypto || me [ 'msCrypto' ] ; if ( crypto ) { const url = 'Uint8ArdomValuesObj012345679BCDEFGHIJKLMNPQRSTWXYZ_cfghkpqvwxyz-' ; _generate = function ( size ) { size = size || 21 ; var id = '' ; var bytes = crypto . getRandomValues ( new Uint8Array ( size ) ) ; while ( 0 < size -- ) { id += url [ bytes [ size ] & 63 ] ; } return id ; } ; } }