class ZeroDepError extends Error{category;source;value;constructor(message="An unexpected error has occurred",category="unknown",source="unknown",value=void 0){super(message),this.category=category,this.source=source,this.value=value,this.name=this.constructor.name,Object.setPrototypeOf(this,new.target.prototype)}}let isFunction=value=>{try{return"[object Function]"===Object.prototype.toString.call(value)}catch{return!1}},guardFunctionHOF=()=>value=>{var error;if(!isFunction(value))throw(error=new ZeroDepError("Value is not a function")).value=value,error},guardFunction=guardFunctionHOF(),isString=value=>{try{return"[object String]"===Object.prototype.toString.call(value)}catch{return!1}},defaultOptions={minLength:void 0,maxLength:void 0},guardStringHOF=(options={})=>{let config={...defaultOptions,...options};return value=>{var error;if(!isString(value))throw(error=new ZeroDepError("Value is not a string")).value=value,error;if(void 0!==config.minLength&&value.lengthconfig.maxLength){let error=new ZeroDepError(`String is longer than ${config.maxLength} character(s)`);throw error.value=value,error}}},guardString=guardStringHOF(),eventEmitterFactory=()=>{let events={};return{on(event,fn){guardString(event),guardFunction(fn),events[event]=events[event]||[],events[event].push(fn)},first(event,fn){guardString(event),guardFunction(fn),events[event]=events[event]||[],events[event].unshift(fn)},once(event,fn){guardString(event),guardFunction(fn);let fnOnce=()=>{fn.apply(this,arguments),this.off(event,fnOnce)};events[event]=events[event]||[],events[event].push(fnOnce)},off(event,fn){guardString(event),guardFunction(fn),events[event]=events[event]||[],events[event]=events[event].filter(f=>f!==fn)},removeAllListeners(event){event?(guardString(event),events[event]=[]):events={}},emit(event,data){guardString(event),events[event]=events[event]||[];for(var fn of events[event])fn(data)}}};exports.eventEmitterFactory=eventEmitterFactory;