!function(f){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=f();else if("function"==typeof define&&define.amd)define([],f);else{var g;g="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,g.eventToPromise=f()}}(function(){return function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}for(var i="function"==typeof require&&require,o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){"use strict";function noop(){}function makeEventAdder(emitter,arrayArg){function addEvent(event,cb){function listener(){cleanUp();var arg,n=arguments.length;if(arrayArg){arg=new Array(n);for(var i=0;i<n;++i)arg[i]=arguments[i];arg.event=event}else arg=n>0?arguments[0]:void 0;cb(arg)}eventsAndListeners.push(event,listener),addListener.call(emitter,event,listener)}var addListener=emitter.addEventListener||emitter.addListener||emitter.on;if(!addListener)throw new Error("cannot register an event listener");var removeListener=emitter.removeEventListener||emitter.removeListener||emitter.off,eventsAndListeners=[],cleanUp=removeListener?function(){for(var i=0,n=eventsAndListeners.length;i<n;i+=2)removeListener.call(emitter,eventsAndListeners[i],eventsAndListeners[i+1])}:noop;return addEvent.cleanUp=cleanUp,addEvent}function eventToPromise(emitter,event,opts){var cancel,promise=new Promise(function(resolve,reject){var addEvent=makeEventAdder(emitter,opts&&opts.array);cancel=function(){cancel=noop,addEvent.cleanUp()},addEvent(event,resolve),opts&&opts.ignoreErrors||addEvent(opts&&opts.error||"error",reject)});return promise.cancel=function(){return cancel()},promise}var defaultErrorEvents=["error"];eventToPromise.multi=function(emitter,successEvents,errorEvents){errorEvents||(errorEvents=defaultErrorEvents);var cancel,promise=new Promise(function(resolve,reject){var addEvent=makeEventAdder(emitter,!0);cancel=function(){cancel=noop,addEvent.cleanUp()};var i,n;for(i=0,n=successEvents.length;i<n;++i)addEvent(successEvents[i],resolve);for(i=0,n=errorEvents.length;i<n;++i)addEvent(errorEvents[i],reject)});return promise.cancel=function(){return cancel()},promise},module.exports=eventToPromise},{}]},{},[1])(1)});
