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

@formdata-helper/remix

v1.1.0

Published

Easy functions for converting formdata instances to an object.

Downloads

257

Readme

@formdata-helper/remix

Easy functions for converting formdata instances to an object.

Why would I use this instead of passing my FormData instance to Object.fromEntries?

There are two big things that Object.fromEntries does not handle. The biggest issue is forms with multiple values under the same key. Creating an object with Object.fromEntries will only grab the last value assigned to this key, even though FormData is storing multiple values for this key. Second, @formdata-helper/base allows for easily assigning a type to the parsed object.

Usage

Use your package manager to install @formdata-helper/remix. This package is meant to be used in a remix app. If you're looking for a library that can be used in the browser check out @formdata-helper/base

@formdata-helper/remix

import { parseForm } from "@formdata-helper/remix"

export const action: ActionFunction = async ({ request }) => {
  // Form has 3 inputs
  // <input name="single" value="foo">
  // <input name="multiple" value="bar">
  // <input name="multiple" value="baz">
  const asObject = await parseForm(request);
  console.log(asObject);
  // Output: { single: 'foo', multiple: ['bar', 'baz'] }
}

Typescript

@formdata-helper fully supports typescript. All functions are shipped with type definitions. You can also define the type of form you are parsing.

import { parseForm } from "@formdata-helper/base"

type Form = {
  single: string;
  multiple: string[];
}

const formdataInstance = new FormData();
formdataInstance.append('single', 'foo');
formdataInstance.append('multiple', 'bar');
formdataInstance.append('multiple', 'baz');
const asObject = parseForm<Form>(formdataInstance);

It may be helpful to use typescript helpers alter the properties to nullable until you validate the fields were filled out correctly.