import EventEmitter from "events" ; export function enumerate < T > ( arr ) { return arr . map ( ( v , i ) => [ i , v ] ) ; } export function divide ( from , split ) { const arr = from . split ( split ) ; return [ arr [ 0 ] , arr . slice ( 1 ) . join ( split ) ] ; } export class PromiseQueue { queue : { promise : ( ) => Promise < any > ; done : ( ) => void ; } [ ] = [ ] ; running = false ; push = ( promise ) => new Promise < void > ( ( r ) => { this . queue . push ( { promise , done : r } ) ; if ( ! this . running ) this . run ( ) ; } ) ; private async run ( ) { const task = this . queue . shift ( ) ; if ( task ) { this . running = true ; await task . promise ( ) ; task . done ( ) ; this . run ( ) ; } else { this . running = false ; } } } export class EventTarget extends EventEmitter { addEventListener = ( type , listener ) => { this . addListener ( type , listener ) ; } ; removeEventListener = ( type , listener ) => { this . removeListener ( type , listener ) ; } ; }