npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@captainpants/zerodeps-multipart-parser

v0.1.0

Published

A zero dependency, high compatibility, multipart HTTP multipart content parser

Downloads

5

Readme

Zero-Dependency High-Compatibility Multipart HTTP Parser and Toolkit (Beta)

See NPM package: @captainpants/zerodeps-multipart-parser

This project's focus is a parser for multi-part HTTP content coming from XMLHttpRequest responses.

Project goals:

  • Make it easy to parse multi-part HTTP responses
  • No runtime dependencies
  • Compatibility with IE11

As a natural progression from this, this library also provides a number of tools to make dealing with HTTP data simpler, including:

  • Easy to use interface to HTTP single part and multipart content via the HttpContent class.
  • The multipart parsing class MultipartParser which will take a DataView (wrapping an ArrayBuffer) and break it into parts according to a given boundary string.
  • Convenient conversion between string, Blob, ArrayBuffer, and DataView via the Data class. This class is similar to the modern Response class, but supports older browsers.
  • Some header utilities for dealing with raw headers, content-type and content-disposition headers (including extended parameters).
  • A light-weight HttpClient that brings a promise-based interface and more comprehensive interfaces to HTTP content over the top of XMLHttpRequest.

Some modern browser functionality has been polyfilled to support IE11. You may opt to use core-js or similar more fully feature (and tested) polyfill packages instead of the ones bundled.

  • Promises - Required to use the library with IE11
  • AbortController - (Optional) Required to support aborting Http requests for HttpClient in IE11.

We hope to support as wide array of old browsers as possible, but in reality as a small open source project our testing resources are limited. As such our main compatibility goal is continued support for IE11 which will hopefully bring along with it other legacy browser versions. We will accept tickets for old browsers where possible and see if there is a practical was to implement support.

Where possible we will use newer browser features to provider better performance.

This is a small example showing the library in action:

import { HttpClient, isMultipartContent, MultipartHttpResponse } from '@captainpants/zerodeps-multipart-parser';

const client = new HttpClient();

const response = await client.request({
    method: 'GET',
    url: 'https://google.com',
    responseType: 'arraybuffer' // 'text' or 'blob' or 'arraybuffer'
});

// now response is either a SingularHttpContent or MultipartHttpContent, and you can check which with a simple instanceof check, or check for the presence of the 'parts' property

if (isMultipartContent(response)) { // or response instanceof MultipartHttpResponse
    let i = 1;
    for (const part of response.parts) {
        console.log(`Part ${i}: ${await part.data.string()}`);

        ++i;
    }

    // alternatively 
    for (const { name, filename, data } of response.entries()) {
        // The entries method is modelled on the structure of FormData.prototype.entries()
    }
}
else {
    // otherwise its a SingularHttpResponse
}

Packaging

We bundle as an esm module with typescript bindings, and also a umd module.

You can find us on npm: @captainpants/zerodeps-multipart-parser

To use our umd module you can access it from unpkg:

  • https://unpkg.com/@captainpants/zerodeps-multipart-parser@latest/dist/umd.js
  • And minified https://unpkg.com/@captainpants/zerodeps-multipart-parser@latest/dist/umd.min.js