import { MessageObjectInfo } from '../MessageObjectInfo'; function isBinary(obj: object): boolean { if (typeof window !== 'undefined' && obj instanceof File) { return true; } return obj instanceof Blob || obj instanceof ArrayBuffer; } function join(left: string, right: string | number): string { const sep = left.length === 0 ? '' : '.'; return `${left}${sep}${right}`; } export function getMessageObjectInfo(obj: any, currentPath: Array = [], accum = new MessageObjectInfo()): MessageObjectInfo { if (Array.isArray(obj)) { obj.forEach((value, index) => getMessageObjectInfo(value, [...currentPath, index], accum)); } else if (isBinary(obj)) { const size = obj.size || obj.byteLength || 0; accum.binaryData.push({ path: currentPath, data: obj, size, }); // eslint-disable-next-line no-param-reassign accum.binarySize += size; } else if (typeof obj === 'object' && obj !== null) { Object.entries(obj).forEach(([key, value]) => getMessageObjectInfo(value, [...currentPath, key], accum)); } return accum; }