# multipart-browser-parser

> Parse multipart response in browser

Latest version **1.0.0** (published 2023-07-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install multipart-browser-parser
pnpm add multipart-browser-parser
yarn add multipart-browser-parser
bun add multipart-browser-parser
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-07-17 |
| First published | 2023-07-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 19.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Kate Miháliková |
| Maintainers | katemihalikova |
| Keywords | multipart, response, fetch, browser |

## Links

- npm: https://www.npmjs.com/package/multipart-browser-parser
- Repository: https://github.com/katemihalikova/multipart-browser-parser
- Homepage: https://github.com/katemihalikova/multipart-browser-parser#readme
- Issues: https://github.com/katemihalikova/multipart-browser-parser/issues
- Funding: https://github.com/sponsors/katemihalikova
- npm.io page: https://npm.io/package/multipart-browser-parser

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2023-07-17
- 1.0.0-alpha.4 — 2023-07-14
- 1.0.0-alpha.3 — 2023-07-14
- 1.0.0-alpha.2 — 2023-07-14
- 1.0.0-alpha.1 — 2023-07-14

## README

# multipart-browser-parser

![npm version](https://img.shields.io/npm/v/multipart-browser-parser)
[![MIT License](https://img.shields.io/badge/License-MIT-green.svg)](https://choosealicense.com/licenses/mit/)

Got an obscure REST endpoint that returns a multipart response and need to parse it directly in browser? This is the package you are looking for! One response in, multiple responses out.


## Installation

Install using npm

```bash
  npm install multipart-browser-parser
```


## Example

```typescript
import {parseMultipartResponse} from "multipart-browser-parser";

async function getMultipartData() {
  let response = await fetch("/api/multipart");
  let {bodyParts} = parseMultipartResponse(response);

  let firstPartAsText = await bodyParts[0].text();
  let secondPartAsJson = await bodyParts[1].json();

  return [firstPartAsText, secondPartAsJson];
}
```


## API Reference

### parseMultipartResponse

▸ **parseMultipartResponse**(`response`, `userOptions?`): `Promise`<[`ParseResult`](interfaces/ParseResult.md)\>

Parse a multipart Response object into separate Response objects

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `response` | `Response` | Multipart Response object |
| `userOptions?` | `Partial`<[`Options`](#options)\> | User-supplied parser configuration |

#### Returns

`Promise`<[`ParseResult`](#parseresult)\>

Separate Response objects, together with any raw preamble and epilogue data

___

### parse

▸ **parse**(`body`, `boundary`, `userOptions?`): [`ParseResult`](#parseresult)

Parse raw multipart data into separate Response objects

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `body` | `ArrayBuffer` \| `Uint8Array` | Multipart raw data |
| `boundary` | `string` | Multipart boundar string |
| `userOptions?` | `Partial`<[`Options`](#options)\> | User-supplied parser configuration |

#### Returns

[`ParseResult`](#parseresult)
Separate Response objects, together with any raw preamble and epilogue data

___

### getBoundary

▸ **getBoundary**(`headerWithBoundary`): `string` \| `undefined`

Parse a boundary string out of a header that contains it as a parameter

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `headerWithBoundary` | `string` | Raw header value or whole raw header |

#### Returns

`string` \| `undefined`
Multipart boundary string

___

### ParseResult

Result of parsing of multipart data

• **bodyParts**: `Response`[]

Separate Response objects parsed from multipart data

• **preamble**: `Uint8Array`

Raw data of any preamble present in multipart body

• **epilogue**: `Uint8Array`

Raw data of any epilogue present in multipart body

___

### Options

User-supplied parser configuration

• **rfcViolationNoBoundaryPrefix**: `boolean`

Flag to set if the Content-Type header already contains

• **rfcViolationNoFirstBoundary**: `boolean`

Flag to set if your response does not contain a preamble and starts with the first part immediately, without a boundary string

___


## License

[MIT](https://choosealicense.com/licenses/mit/)

---
_Source: https://npm.io/package/multipart-browser-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
