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

object-2-formdata

v0.0.4

Published

JavaScript Class that creates form data from complex objects.

Downloads

11

Readme

Object 2 FormData

Form Data Class For Transforming complex Objects into Form Data

With O2F, you can:

  • Create FormData from Complex Data Structures for use in HTTP Methods.
  • Convert Files nested within Objects/Arrays
  • POST/PATCH Objects of any size

Why you should use Object-2-FormData

O2F is an Object Class that recursively traverses Objects neatly into FormData in such a way that they are exactly represented when parsed on the backend. This includes: Files, Arrays, Objects, & Primitive Data-Types.

Install

# NPM
npm install object-2-formdata --save

Adding to your project

In Node.js

import { ObjectToForm } from "object-2-formdata";

Example:

Front-End
const form = new ObjectToForm(<Object>, <String>);

Object:

  • Required
  • Object to parse into Form Data

String:

  • Not Required
  • Base String eg.('payload')

Back-End:

var payload = serializeObject(JSON.parse(JSON.stringify(payload)));
payload: {
  metadata: { createdBy: 'test-admin', uploaded: '2022-08-27T02:06:33.678Z' },
  id: '519dc76b-3b2f-47cd-9958-8518066318aa',
  title: 'Test',
  cover: {
    contentsUrl: 'https://www.test.com'
  },
  volumes: 1,
  summary: 'Some Summary',
  authors: [ 'Howardbleu' ],
  themes: [ 'Combat Sports' ],
  genre: [ 'Award Winning' ],
  status: 'Publishing',
  chapters: [
    { volume: 0, number: 0, releaseDate: '2022-09-06T00:00:00Z' },
    { volume: 0, number: 0, releaseDate: '2022-09-21T00:00:00Z' }
  ],
  __v: 0
}

files: [
  {
    fieldname: 'patch[chapters][0][file]',
    originalname: 'Test1.jpg',
    encoding: '7bit',
    mimetype: 'image/jpeg',
    buffer: <Buffer ff d8 ff e1 01 f2 45 78 69 66 00 00 4d 4d 00 2a 00 00 00 08 00 08 01 0e 00 02 00 00 00 65 00 00 00 6e 01 1a 00 05 00 00 00 01 00 00 00 d4 01 1b 00 05 ... 3589046 more bytes>,
    size: 3589096
  },
  {
    fieldname: 'patch[chapters][1][file]',
    originalname: 'Test2.png',
    encoding: '7bit',
    mimetype: 'image/png',
    buffer: <Buffer 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 00 00 0d 79 00 00 13 31 08 00 00 00 00 46 38 92 c0 00 00 00 1a 74 45 58 74 41 75 74 68 6f 72 00 64 61 ... 3382048 more bytes>,
    size: 3382098
  }
]

License

MIT