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

form-jsonizer

v1.0.0

Published

Serializes HTML5 forms to JSON

Downloads

2

Readme

Build Status Coverage Status

Synopsis

Some times all you want is a simplier way to transform your html forms in json or js objects. This is what this projet is about.

Code Example

Consider a simple markup like this:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <form action="#" id="myForm">
    <input type="checkbox" name="checkbox" value="checkbox" checked disabled>
    <input type="color" name="color" value="#FF0000" disabled>
    <input type="date" name="date" value="2017-11-24" disabled>
    <input type="datetime" name="datetime" value="2017-11-24T04:30" disabled>
    <input type="datetime-local" name="datetime-local" value="2017-11-24T04:30" disabled>
    <input type="email" name="email" value="[email protected]">
    <input type="file" name="file">
    <input type="hidden" name="hidden" value="hidden">
    <input type="image" src="image" alt="image input">
    <input type="month" name="month" value="2017-11">
    <input type="number" name="number" value="12345">
    <input type="password" name="password" value="password">
    <input type="radio" name="radio" value="radio" checked>
    <input type="radio" name="radio" value="radio2">
    <input type="range" name="range" value="35">
    <input type="search" name="search" value="search">
    <input type="tel" name="tel" value="(61)99304-1307">
    <input type="text" name="text" value="text">
    <input type="time" name="time" value="04:30">
    <input type="url" name="url" value="http://www.google.com">
    <input type="week" name="week" value="2017-W47">
    <input type="reset" value="reset">
    <input type="button" value="button">
    <input type="submit" value="">
    <textarea name="textarea" cols="30" rows="10">textarea</textarea>
    <select name="select">
      <option value="select" selected>select</option>
    </select>
  </form>
</body>
</html>

Then all you have to do is create a new instance of FormJsonizer and call the serializer method. Don't forget passing the form object as the first parameter! Take a look:

const jsonizer = new FormJsonizer();
const form =  document.getElementById('myForm');
const json = jsonizer.serialize(form);

And voilà, you get this json:

{
	"email": "[email protected]",
	"hidden": "hidden",
	"month": "2017-11",
	"number": "12345",
	"password": "password",
	"radio": "radio",
	"range": "35",
	"search": "search",
	"tel": "(61)99304-1307",
	"text": "text",
	"time": "04:30",
	"url": "http://www.google.com",
	"week": "2017-W47",
	"textarea": "textarea"
}

There is some other tricks you can do:

If you whant disabled fields to be included in the output just say it when you instanciate the class, pretty nice hã?

const jsonizer = new FormJsonizer({ includeDisabled: true })

And if you preffer output a JS object instead of a json there is no problem...

const jsonizer = new FormJsonizer({ json: false });

Motivation

This is a pretty simple project, and learning and having fun was the main motivation bahind this code, and of course, trying to solve some problems of the real world.

Installation

There's no secret:

npm install form-jsonizer -s

Tests

After clone the project just open the folder and execute de command bellow:

npm test

Contributors

Feel free to contribut, just keep in mind the code pattern of the project and be happy! :)

License

Do whatever you want with this code! Enjoy, it is distributed under MIT license.