UNPKG

@waboyz-baileys/shared

Version:

35 lines (34 loc) 1.1 kB
import { Binary } from "mongodb"; export function convertOnlyBuffersToBase64(obj) { if (Array.isArray(obj)) { return obj.map(convertOnlyBuffersToBase64); } if (Buffer.isBuffer(obj) || obj instanceof Binary) { return obj.toString('base64'); } if (obj && typeof obj === 'object' && !(obj instanceof Date) && !(obj instanceof RegExp)) { const result = {}; for (const key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { const value = obj[key]; if (value && typeof value === 'object' && 'low' in value && 'high' in value && 'unsigned' in value && typeof value.low === 'number' && typeof value.high === 'number') { result[key] = value; } else { result[key] = convertOnlyBuffersToBase64(value); } } } return result; } return obj; }