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

simple-multipart-formdata

v1.0.2

Published

To parase multipart form data body to a JSON object

Downloads

1

Readme

simple-multipart-formdata

Installation :

npm install simple-multipart-formdata

- Simple API to parse multipart-formdata into a readable object.

- Only requires HTTP request as an input which then return an event emitter. This will emit data event when form-data is ready. You need to assign an event listener to consume data which is coming as a readable object.

Note : It will not work with static types such as files. This works really well with all other types.

Example


const { formation } = require('simple-multipart-formdata');

let    Form         =  formation( req ); 

Form.on( 'data' , (data)=> {

    // do something
    // data is readable object, containing parsed request body data
})

Explanation

formation( req ) get the HTTP request stream and return an event emitter which is fired when multipart-form-data has properly parsed.This is the main API of this module.

Form ( you can name this as you want ) is stored the return value which is an Event emitter

API

formation( [stream] )

return : emitter

Full Example :

HTTP Server which is handling incoming requests.

      else if(req.method == "POST"){

        let Info = {} ;
       
        let Form = formation( req );     /* 'formation' do the body parsing and return a event emitter which emit -
                                            when data is available */

        Form.on('data' , (data)=> { 
            Info = data ;
            console.log( data );  // to see how output looks like 
        });
       
        req.on( 'end' , ()=> {

            res.writeHead( 200 , { 'Content-Type': 'application/json'})
            res.end( JSON.stringify(Info) );         // to see the parsed form-data

        })
      
   }

Here is the relavent html code.

       <form action="http://localhost:8000" method="POST" enctype="multipart/form-data">
        
        <input type="text" name="MYtext">
        <input type="datetime-local" name="MYdatetime">
        <input type="month" name="MYmonth">
        <input type="time" name="Mytime">
        <input type="search" name="MYsearch">
       
        <input type="submit" name="SUBMITTED">

    </form>

Here is the Output looks like.

{
  MYtext: 'Gold Fish',
  MYdatetime: {
    date: '2021-10-01',
    year: '2021',
    month: '10',
    day: '01',
    time: '00:25',
    hour: '00',
    minute: '25'
  },
  MYmonth: { date: '2021-01', year: '2021', month: '01' },
  Mytime: { time: '20:15', hour: '20', minute: '15' },
  MYsearch: 'search for something',
  SUBMITTED: 'Submit'
}

NICE ahh ............ :smiley::smiley:

following table shows the field(key) and data format of return object

| type | data format | |----------------------------------|----------------------| |checkbox , text , color , email | text/plain | |number , password , radio , range | text/plain | |search , tel , url | text/plain | |date |{ date,YY,MM,DD } | |datetime-local |{ datetime,YY,MM,DD,HR,MIN }| |month |{ date,YY,MM } | |week |{ date,YY,WW } | |time |{ time,HR,MIN } |

Here ;

YY -> year , MM -> month , WW -> week , DD -> day , HR -> hour , MIN -> minute