{"library":"meros","title":"Meros: Multipart Response Utility","description":"Meros is a lightweight (642B gzipped) utility designed to simplify the parsing of `multipart/mixed` HTTP responses, a common pattern in technologies like GraphQL for deferred or streamed results. Currently at version 1.3.2, the project appears actively maintained with a stable release cadence. Its key differentiators include a zero-dependency runtime, a minimal footprint, high performance, and seamless integration with `fetch` and `rxjs`. It supports both Node.js (requiring `node >=13`) and browser environments, automatically parsing JSON content within parts. Meros returns an `AsyncGenerator` for `multipart/mixed` responses, or the original `Response` object for other content types, offering flexibility for use in middleware or chained `fetch` calls.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install meros"],"cli":null},"imports":["import { meros } from 'meros';","import { meros } from 'meros/browser';","import { meros } from 'meros/node';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { meros } from 'meros';\n\nasync function fetchAndProcessMultipart() {\n  // Simulate a multipart/mixed response or a regular JSON response\n  // In a real application, replace with your actual fetch call\n  const mockFetch = async (url: string) => {\n    if (url === '/api/multipart') {\n      // Example multipart response\n      return new Response(\n        `--boundary\\r\\nContent-Type: application/json\\r\\n\\r\\n{\"data\": \"part1\"}\\r\\n--boundary\\r\\nContent-Type: text/plain\\r\\n\\r\\nhello from part 2\\r\\n--boundary--`,\n        {\n          headers: { 'Content-Type': 'multipart/mixed; boundary=boundary' }\n        }\n      );\n    } else {\n      // Example non-multipart JSON response\n      return new Response(JSON.stringify({ message: 'Not multipart' }), {\n        headers: { 'Content-Type': 'application/json' }\n      });\n    }\n  };\n\n  try {\n    const response = await mockFetch('/api/multipart'); // Try with '/api/json' to see the other path\n    const parts = await meros(response);\n\n    if (parts && typeof (parts as any)[Symbol.asyncIterator] === 'function') {\n      console.log('Processing multipart response:');\n      for await (const part of parts) {\n        if (part.json) {\n          console.log('  JSON Part:', part.body);\n        } else {\n          console.log('  Text/Other Part:', new TextDecoder().decode(part.body as Uint8Array));\n        }\n      }\n    } else {\n      console.log('Not a multipart response, processing as regular response:');\n      const data = await (parts as Response).json();\n      console.log('  Response Data:', data);\n    }\n  } catch (error) {\n    console.error('Error fetching or processing:', error);\n  }\n}\n\nfetchAndProcessMultipart();","lang":"typescript","description":"Demonstrates fetching a response, processing it with `meros`, and gracefully handling both `multipart/mixed` and non-multipart (e.g., JSON) responses using an async generator pattern.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}