UNPKG

@redocly/cli

Version:

[@Redocly](https://redocly.com) CLI is your all-in-one API documentation utility. It builds, manages, improves, and quality-checks your API descriptions, all of which comes in handy for various phases of the API Lifecycle. Create your own rulesets to make

32 lines 1.21 kB
export function jsonStringifyWithArrayBuffer(obj, space) { const MAX_SIZE = 1024 * 1024; // 1MB return JSON.stringify(obj, (key, value) => { if (value instanceof ArrayBuffer) { if (value.byteLength > MAX_SIZE) { return { __type: 'ArrayBuffer', data: `File too large to serialize (${value.byteLength} bytes). Maximum allowed size is ${MAX_SIZE} bytes.`, byteLength: value.byteLength, }; } const uint8Array = new Uint8Array(value); const base64 = Buffer.from(uint8Array).toString('base64'); return { __type: 'ArrayBuffer', data: base64, byteLength: value.byteLength, }; } if (value instanceof File) { return { __type: 'File', name: value.name || '[File Object]', size: value.size || 0, type: value.type || '', lastModified: value.lastModified || 0, }; } return value; }, space); } //# sourceMappingURL=json-stringify-with-array-buffer.js.map