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 isArray=value=>{try{return Array.isArray(value)}catch{return!1}},isBigInt=value=>{try{return"bigint"==typeof value}catch{return!1}},isBoolean=value=>{try{return"[object Boolean]"===Object.prototype.toString.call(value)}catch{return!1}},isDate=value=>{if("[object Date]"!==Object.prototype.toString.call(value))return!1;if("Invalid Date"===value)return!1;try{var ms=value.getTime();return!Number.isNaN(ms)}catch{return!1}},isNil=value=>{try{return null==value}catch{return!1}},isNumber=value=>{try{return"[object Number]"===Object.prototype.toString.call(value)&&Math.abs(value)!==1/0&&!Number.isNaN(value)}catch{return!1}},isPromise=value=>{try{return"[object Promise]"===Object.prototype.toString.call(value)}catch{return!1}},isSet=value=>{try{return"[object Set]"===Object.prototype.toString.call(value)}catch{return!1}},isString=value=>{try{return"[object String]"===Object.prototype.toString.call(value)}catch{return!1}},isTypedArray=value=>{try{return-1!==["[object BigInt64Array]","[object BigUint64Array]","[object Float32Array]","[object Float64Array]","[object Int16Array]","[object Int32Array]","[object Int8Array]","[object SharedArrayBuffer]","[object Uint16Array]","[object Uint32Array]","[object Uint8Array]","[object Uint8ClampedArray]"].indexOf(Object.prototype.toString.call(value))}catch{return!1}},isWeakMap=value=>{try{return"[object WeakMap]"===Object.prototype.toString.call(value)}catch{return!1}},isWeakSet=value=>{try{return"[object WeakSet]"===Object.prototype.toString.call(value)}catch{return!1}},isFunction=value=>{try{var type=Object.prototype.toString.call(value);return"[object Function]"===type||"[object AsyncFunction]"===type}catch{return!1}},replacer=(_key,value)=>{var type=Object.prototype.toString.call(value);if("[object BigInt]"===type||"[object Date]"===type)return value.toString();if("[object Set]"===type)return[...value];if("[object Map]"===type)return Object.fromEntries(value);if("[object Array]"!==type&&"[object BigInt]"!==type&&"[object Boolean]"!==type&&"[object Null]"!==type&&"[object Number]"!==type&&"[object Object]"!==type&&"[object String]"!==type&&"[object Undefined]"!==type)throw(type=new ZeroDepError(errMessage)).value=value,type;return value},errMessage="Cannot convert to JSON",toPojo=value=>{var error,type=Object.prototype.toString.call(value);if("[object Null]"===type||"[object Undefined]"===type)return null;if("[object Array]"!==type&&"[object Map]"!==type&&"[object Object]"!==type&&"[object Set]"!==type&&"[object Function]"!==type&&"[object AsyncFunction]"!==type)throw(error=new ZeroDepError(errMessage)).value=value,error;let maybeJson;"toJSON"in value&&isFunction(value.toJSON)&&(maybeJson=value.toJSON());try{return JSON.parse(JSON.stringify(maybeJson??value,replacer))}catch(error){type=new ZeroDepError(errMessage);throw error.value&&(type.value=error.value),type}},toString=value=>{if(isString(value))return value;if(isNil(value))return"";if(isBoolean(value))return value?"true":"false";if(isDate(value))return value.toISOString();if(isNumber(value))return""+value;if("[object Number]"===Object.prototype.toString.call(value))return String(value);if(isBigInt(value))return value.toString();if(isArray(value)||isSet(value)){var item,items=[];for(item of[...value])items.push(toString(item));return items.join(", ")}var error;if(isWeakSet(value)||isWeakMap(value)||isTypedArray(value)||isPromise(value))throw(error=new ZeroDepError("Cannot convert to string")).value=value,error;try{return JSON.stringify(toPojo(value))}catch{let error=new ZeroDepError("Cannot convert to string");throw error.value=value,error}},hash=val=>{var str=toString(val);let hash=5381,i=str.length;for(;i;)hash=33*hash^str.charCodeAt(--i);return hash>>>0},structCollectionFactory=(items=[])=>{let collection=new Map;for(var item of items){var key=hash(toString(item));collection.set(key,item)}return{fromArray:data=>{for(var item of data){var key=hash(toString(item));collection.set(key,item)}},toArray:()=>[...collection.values()],add:item=>{var key=hash(toString(item));collection.has(key)||collection.set(key,item)},has:item=>{item=hash(toString(item));return collection.has(item)},values:()=>collection.values(),size:()=>collection.size,delete:item=>{item=hash(toString(item));collection.delete(item)},clear:()=>collection.clear(),union:otherCollection=>{var value,unionCollection=structCollectionFactory();for(value of collection.values())unionCollection.add(value);for(let value of otherCollection.values())unionCollection.add(value);return unionCollection},intersection:otherCollection=>{var item,intersectionCollection=structCollectionFactory();for(item of collection.values())otherCollection.has(item)&&intersectionCollection.add(item);return intersectionCollection},difference:otherCollection=>{var item,differenceCollection=structCollectionFactory();for(item of collection.values())otherCollection.has(item)||differenceCollection.add(item);return differenceCollection},isSubsetOf:otherCollection=>[...collection.values()].every(item=>otherCollection.has(item)),[Symbol.iterator](){let items=[...collection.values()],ndx=0;return{next(){return ndxvalue=>{var error;if(!isFunction(value))throw(error=new ZeroDepError("Value is not a function")).value=value,error},guardFunction=guardFunctionHOF(),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)}}},structQueueFactory=(name,data=[])=>{let items=[...data],{emit,removeAllListeners,...eventEmitterMethods}=eventEmitterFactory();return{fromArray:data=>{items=[...data]},toArray:()=>items,enqueue:item=>{items.push(item),emit("enqueued",{name:name,ts:Date.now(),payload:item})},dequeue:()=>{var item=items.shift();return item&&(emit("dequeued",{name:name,ts:Date.now(),payload:item}),0===items.length)&&emit("emptied",{name:name,ts:Date.now()}),item},front:()=>items[0],clear:()=>{0items.length,isEmpty:()=>0===items.length,...eventEmitterMethods}},structLinkedListFactory=(data=[])=>{let headNode=null,tailNode=null,size=0,linkedList={size:()=>size,getHead:()=>headNode,getTail:()=>tailNode,prepend:data=>{data={data:data,prev:null,next:headNode||null};size+=1,headNode=data,tailNode=tailNode||data},append:data=>{data={data:data,prev:tailNode||null,next:null};size+=1,tailNode&&(tailNode.next=data),tailNode=data,headNode=headNode||data},find:comparator=>{let checkNext=node=>comparator(node.data)?node:node.next?checkNext(node.next):null;return headNode?checkNext(headNode):null},insertBefore:(node,data)=>{data={data:data,prev:node.prev,next:node};size+=1,node.prev?node.prev.next=data:headNode=data,node.prev=data},insertAfter:(node,data)=>{data={data:data,prev:node,next:node.next};size+=1,node.next?node.next.prev=data:tailNode=data,node.next=data},deleteNode:node=>{node.prev?node.prev.next=node.next||null:headNode=node.next||null,node.next?node.next.prev=node.prev||null:tailNode=node.prev||null,--size},deleteHead:()=>{var headNode=linkedList.getHead();headNode&&linkedList.deleteNode(headNode)},deleteTail:()=>{var tailNode=linkedList.getTail();tailNode&&linkedList.deleteNode(tailNode)},clear:()=>{headNode=null,tailNode=null,size=0},toArray:()=>{let array=[];if(!headNode)return array;let addToArray=node=>(array.push(node.data),node.next?addToArray(node.next):array);return addToArray(headNode)},toArrayReverse:()=>{let array=[];if(!tailNode)return array;let addToArray=node=>(array.push(node.data),node.prev?addToArray(node.prev):array);return addToArray(tailNode)},[Symbol.iterator](){let node=headNode;return{next(){let value=null,done=!0;return null!==node&&(value=node.data,done=!1,node=node.next),{value:value,done:done}}}}};for(var datum of data)linkedList.append(datum);return linkedList},structStackFactory=(data=[])=>{let items=[...data];return{fromArray:data=>{items=[...data]},toArray:()=>items,push:item=>{items.push(item)},pop:()=>items.pop(),peek:()=>items.slice(-1)[0],clear:()=>{items=[]},size:()=>items.length}},getType=Object.prototype.toString,compare=(a,b)=>{if(Object.is(a,b))return!0;if(null==a||null==b)return!1;var typeA=Array.isArray(a)?"Array":getType.call(a).slice(8,-1);if(typeA!==(Array.isArray(b)?"Array":getType.call(b).slice(8,-1)))return!1;switch(typeA){case"Array":if(a.length!==b.length)return!1;for(var ndx in a)if(!compare(a[ndx],b[ndx]))return!1;return!0;case"ArrayBuffer":var dvA=new DataView(a),dvB=new DataView(b);return compare(dvA,dvB);case"Boolean":return!!a==!!b;case"DataView":if(a.byteLength!==b.byteLength)return!1;for(let i=0;i!compare(a[key],b[key])):!1;case"Map":return a.size!==b.size?!1:(dvB=[...a.keys()],dvA=[...b.keys()],dvB.length===dvA.length&&!!compare(dvB,dvA)&&(dvB=[...a.values()],dvA=[...b.values()],compare(dvB,dvA)));case"Set":dvB=[...a].sort(),dvA=[...b].sort();return compare(dvB,dvA);case"BigInt64Array":case"BigUint64Array":case"Float32Array":case"Float64Array":case"Int16Array":case"Int32Array":case"Int8Array":case"Uint16Array":case"Uint32Array":case"Uint8Array":case"Uint8ClampedArray":return a.byteLength===b.byteLength?a.every((value,ndx)=>value===b[ndx]):!1;case"BigInt":case"Number":case"Promise":case"String":case"Generator":return!1;default:dvB=new ZeroDepError(`Cannot compare ${typeA} values`);throw dvB.value=a,dvB}},isEqual=(val1,val2)=>{try{return compare(val1,val2)}catch(err){if(err instanceof ZeroDepError)throw err;return!1}},structTreeFactory=json=>{let rootNode=null,tree={getRootNode:()=>rootNode,setRootNode:data=>{if(rootNode)throw new ZeroDepError("Root node already defined");return rootNode={data:data,parent:null,children:null}},addChild:(node,data)=>{node.children=node.children||[];data={data:data,parent:node,children:null};return node.children.push(data),data},addChildren:(node,items)=>{node.children=node.children||[];items=items.map(data=>({data:data,parent:node,children:null}));return node.children.push(...items),items},dfs:comparator=>{if(!rootNode)return null;let match=null,searchDepthFirst=children=>{for(var child of children){if(match)return;if(comparator(child.data))return void(match=child);child.children&&searchDepthFirst(child.children)}};return rootNode.children&&searchDepthFirst(rootNode.children),match},bfs:comparator=>{if(!rootNode)return null;let match=null,searchBreadthFirst=children=>{for(var child of children){if(match)return;if(comparator(child.data))return void(match=child)}for(let child of children)!match&&child.children&&searchBreadthFirst(child.children)};return rootNode.children&&searchBreadthFirst(rootNode.children),match},dfsFilter:comparator=>{if(!rootNode)return[];let matches=[],searchDepthFirst=children=>{for(var child of children)comparator(child.data)&&matches.push(child),child.children&&searchDepthFirst(child.children)};return rootNode.children&&searchDepthFirst(rootNode.children),matches},bfsFilter:comparator=>{if(!rootNode)return[];let matches=[],searchBreadthFirst=children=>{for(var child of children)comparator(child.data)&&matches.push(child);for(let child of children)child.children&&searchBreadthFirst(child.children)};return rootNode.children&&searchBreadthFirst(rootNode.children),matches},deleteNode:node=>{var parentNode;node.parent?((parentNode=node.parent).children=parentNode.children.filter(child=>!isEqual(node.data,child.data)),parentNode.children.length||(parentNode.children=null)):rootNode=null},toJSON:()=>{if(!rootNode)return null;var obj={data:rootNode.data,children:[]};let getChildren=children=>children.map(child=>({data:child.data,children:child.children?getChildren(child.children):void 0}));return obj.children=rootNode.children?getChildren(rootNode.children):void 0,obj}};if(json){let{children=null,data=void 0,...rest}=json;json=tree.setRootNode(data||rest);let populateChildren=(node,children)=>{for(var child of children){let{children,data,...rest}=child;child=tree.addChild(node,data??rest);children&&populateChildren(child,children)}};children&&populateChildren(json,children)}return tree};exports.structCollectionFactory=structCollectionFactory,exports.structLinkedListFactory=structLinkedListFactory,exports.structQueueFactory=structQueueFactory,exports.structStackFactory=structStackFactory,exports.structTreeFactory=structTreeFactory;