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

@h7/compute-js-formdata

v0.1.0

Published

FormData parser and Request.prototype.formData() polyfill for JavaScript. A formal version is coming in the JS runtime, but this can be used in the interim.

Downloads

8

Readme

FormData parsing for Fastly Compute JavaScript

by Katsuyuki Omuro

Parses body streams of type multitype/form-data and provides them as a polyfill for Request.prototype.formData() and Response.prototype.formData(). This is meant to be used with Fastly Compute, but can probably be used with any platform that happens to provide Request/Response but not .prototype.formData().

Eventually, we expect to see native implementations to be coming to the Fastly Compute JavaScript runtime, and they will be more performant, but this polyfill can be used in the meantime.

Prerequisites

This polyfill does depend on the data structures File and FormData, which at the current time will themselves also need polyfills. blob-polyfill and formdata-polyfill seem to work.

You may face a gotcha when doing this; see the Caveats section below.

Usage

In your Compute project:

npm install blob-polyfill formdata-polyfill @h7/compute-js-formdata

Then, at the beginning of your program:

Object.assign(globalThis, require('blob-polyfill'));
require('formdata-polyfill');
require('@h7/compute-js-formdata');

Now, you can use formData():

const req = event.request;
const formData = await req.formData();
formData.get('foo'); // Value of form field 'foo'

Caveats

blob-polyfill

blob-polyfill does not automatically make its exports available globally, so you'll have to be sure to copy its exported members such as Blob and File to globalThis so that they are available to the other polyfills and to your program.

You can do this like this:

// require and merge with globalThis
Object.assign(globalThis, require('blob-polyfill'));

// require other polyfills
require('formdata-polyfill');
require('@h7/compute-js-formdata');

If you're using ES modules (i.e., import rather than require()) you'll have to be extra careful, because import statements get hoisted.

You'll want to place your blob-polyfill import in a separate file, e.g.:

// load-blob-polyfill.js
import * as blobPolyfill from 'blob-polyfill';
Object.assign(globalThis, blobPolyfill);

And then import that before the FormData polyfill:

// load blob polyfill and make global
import './load-blob-polyfill.js'

// load other polyfills
require('formdata-polyfill');
require('@h7/compute-js-formdata');

License

MIT.