import{DataError}from"./errors.js";import valueToKey from"./valueToKey.js";const getType=x=>{if("number"==typeof x)return"Number";if(x instanceof Date)return"Date";if(Array.isArray(x))return"Array";if("string"==typeof x)return"String";if(x instanceof ArrayBuffer)return"Binary";throw new DataError},cmp=(first,second)=>{if(void 0===second)throw new TypeError;first=valueToKey(first),second=valueToKey(second);const t1=getType(first),t2=getType(second);if(t1!==t2)return"Array"===t1?1:("Binary"!==t1||"String"!==t2&&"Date"!==t2&&"Number"!==t2)&&("String"!==t1||"Date"!==t2&&"Number"!==t2)?"Date"===t1&&"Number"===t2?1:-1:1;if("Binary"===t1&&(first=new Uint8Array(first),second=new Uint8Array(second)),"Array"===t1||"Binary"===t1){const length=Math.min(first.length,second.length);for(let i=0;i<length;i++){const result=cmp(first[i],second[i]);if(0!==result)return result}return first.length>second.length?1:first.length<second.length?-1:0}if("Date"===t1){if(first.getTime()===second.getTime())return 0}else if(first===second)return 0;return first>second?1:-1};export default cmp;