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 🙏

© 2026 – Pkg Stats / Ryan Hefner

body-disposal

v0.0.3

Published

Connect middleware to clean empty fields and delete those specified in _delete

Downloads

13

Readme

bodyDisposal

A simple connect middleware which manipulate your req.body and clean the crime scene.

What will it do?

If you're using the default configuration (do it):

  • Every form field which gets submitted as empty ('' - as in ?password=&..) will be deleted.

  • Every deleted field whose name is contained in the req.body._delete array (or is req.body._delete) will be set to undefined.

You just need to add it to your middlewares (after req.body has been set):

connect.use(bodyDisposal())

If you really want to change something (at your own risk):

connect.use(
  bodyDisposal('_delete', 
    // key used to contain the names of the fields which have to be killed
  {
    deleteData: false,        
      // If this is true, you will be able to delete field submitted with data
      // Don't do it, being able to delete something ONLY when it's empty 
      // is pretty handy 
    deleteValue: undefined
      // When set to something the `deleted field` will contain something.
      // Yeah, I know, surprising. 
      // Changing it doesn't make sense - unless you're ignoring undefined
      // values and you won't actually delete the data. In that case I'd 
      // still go about detecting undefined.
  })
)

Why?

The rationale behind this little project is having a set of well defined rules to avoid being captured in the suckyness of web forms:

  • Ignore empty fields
  • If you want to set a field as empty you have to say it

By ignoring the inputs left empty by default, you can easily send partial form to update only the data you want:

$.post({ 
  username: username,
  avatar: avatar
})

It also make things simpler for fields who are not supposed to be pre-populated again:

<input type="text" name="username" value="framp">
<input type="password" name="password" value="">

In this way creating a checkbox which can be used as a toggle button is as easy as writing:

<input type="checkbox" name="toggle" {?toggle}checked{/toggle}>
<input type="hidden" name="_delete" value="toggle">

Sweet!

What about multiple fields?

<input type="checkbox" name="toggles_0" value="checked" {_.toggles_0}>
<input type="hidden" name="_delete[0]" value="toggles_0">
<input type="checkbox" name="toggles_1" value="checked" {_.toggles_1}>
<input type="hidden" name="_delete[1]" value="toggles_1">
<input type="checkbox" name="toggles_2" value="checked" {_.toggles_2}>
<input type="hidden" name="_delete[2]" value="toggles_2">

Creating an optional field which can be updated as empty in the future is pretty simple too:

<input type="hidden" name="_delete" value="optionalDescription">
<textarea name="optionalDescription"></texarea>

Need to delete something?

$.post({ 
  _delete: 'avatar'
})

Why not use a _keep instead of _delete?

It's just a matter of taste.

I simply found myself having more fields to keep than fields to delete.

License

MIT