Gathering detailed insights and metrics for dom-form-serializer
Gathering detailed insights and metrics for dom-form-serializer
Gathering detailed insights and metrics for dom-form-serializer
Gathering detailed insights and metrics for dom-form-serializer
@teamteanpm2024/eligendi-consectetur-eius
security holding package
@teamteanpm2024/officiis-sint-dolorum
<div align="center"> <p align="center"> <a href="https://react-hook-form.com" title="React Hook Form - Simple React forms validation"> <img src="https://raw.githubusercontent.com/bluebill1049/react-hook-form/master/docs/logo.png" a
@crabas0npm2/culpa-eius-deserunt
security holding package
@crabas0npm2/molestias-accusantium-perspiciatis
security holding package
npm install dom-form-serializer
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
40 Stars
26 Commits
5 Forks
2 Watchers
8 Branches
3 Contributors
Updated on Jan 19, 2024
Latest Version
2.0.0
Package Id
dom-form-serializer@2.0.0
Unpacked Size
87.22 kB
Size
16.57 kB
File Count
21
NPM Version
6.14.8
Node Version
12.20.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Serialize forms fields into a JSON representation.
This project is a fork of Backbone.Syphon that has no dependency on backbone and jquery. It aims to make it easy to serialize the fields of a form into a simple JSON object.
npm install dom-form-serializer
1var serialize = require('dom-form-serializer').serialize 2serialize(document.querySelector('#form'))
The default behavior for serializing fields is to use the field's "name" attribute as the key in the serialized object.
1<form id="form"> 2 <input name="a"> 3 <select name="b"></select> 4 <textarea name="c"></textarea> 5</form>
1serialize(document.querySelector('#form')) 2 3// will produce => 4 5{ 6 a: "", 7 b: "", 8 c: "" 9}
By default, a checkbox will return a boolean value signifying whether or not it is checked.
1<form id="form"> 2 <input type="checkbox" name="a"> 3 <input type="checkbox" name="b" checked> 4 <input type="checkbox" name="c" indeterminate> 5</form>
1serialize(document.querySelector('#form')); 2 3// will produce => 4 5{ 6 a: false, 7 b: true, 8 c: null 9}
Radio button groups (grouped by the input element "name" attribute) will produce a single value, from the selected radio button.
1<form id="form"> 2 <input type="radio" name="a" value="1"> 3 <input type="radio" name="a" value="2" checked> 4 <input type="radio" name="a" value="3"> 5 <input type="radio" name="a" value="4"> 6</form>
1serialize(document.querySelector('#form')) 2 3// will produce => 4 5{ 6 a: "2" 7}
This behavior can be changed by registering a different set of Key Extractors, Input Readers, and Key Assignment Validators. See the tests serialize.spec.js for more examples on these.
Serializing drop down lists (<select>
) will result in value of the selected option.
1<form id="form"> 2 <select name="foo"> 3 <option value="bar"></option> 4 </select> 5</form>
1serialize(document.querySelector('#form')) 2 3// will produce => 4 5{ 6 foo: "bar" 7}
Serializing multiple select boxes (<select multiple>
) will yield the selected options as an array.
1<form id="form"> 2 <select name="foo" multiple> 3 <option value="foo"></option> 4 <option value="bar" selected></option> 5 <option value="baz" selected></option> 6 </select> 7</form>
1serialize(document.querySelector('#form')) 2 3// will produce => 4 5{ 6 foo: ["bar", "baz"] 7}
You can also deserialize an object's values back into their field equivalent. It uses the same conventions and configuration as the serialization process, with the introduction of Input Writers to handle populating the fields with the values
1<form id="form"> 2 <input type="text" name="a"> 3 <input type="text" name="b"> 4</form>
1var data = { 2 a: "foo", 3 b: "bar" 4}; 5 6deserialize(document.querySelector('#form'), data);
This will populate the form field elements with the correct values from the data
parameter.
The following types of input are ignored, and not included in the resulting JavaScript object:
<input type="submit">
buttons<input type="reset"
> buttons<button>
tagsIf you need to get a value from the specific button that was clicked, you can use a DOM event to listen for that element being manipulated (clicked, for example) and manually grab the data you need.
You can define ignored selectors using the ignoredTypes option.
1// ignore all <textarea> input elements 2serialize(element, {ignoredTypes: ['textarea']})
serialize
will parse nested attribute names and create a nested result object, using the Rails standard of name="foo[bar][baz]"
by default.
1<form> 2 <input type="text" name="foo[bar]" value="a value"> 3 <input type="text" name="foo[baz][quux]" value="another value"> 4</form>
will produce
1{ 2 foo: { 3 bar: "a value", 4 baz: { 5 quux: "another value" 6 } 7 } 8}
serialize
will parse multiple inputs named after the convention name="foo[bar][]"
into elements of the array bar
.
1<form> 2 <input type="checkbox" name="foo[bar][]" value="baz" checked="checked"> 3 <input type="checkbox" name="foo[bar][]" value="qux" checked="checked"> 4</form>
will produce
1{ 2 foo: { 3 bar: ["baz", "qux"] 4 } 5}
If your keys are split by something else than the Rails Array convention (for example name="foo.bar.quux"
), you may pass this delimiter into serialize
using the keySplitter
option.
1<form id="form"> 2 <input type="text" name="widget" value="wombat"> 3 <input type="text" name="foo.bar" value="baz"> 4 <input type="text" name="foo.baz.quux" value="qux"> 5</form>
1serialize(document.querySelector('#form'), { keySplitter: key => key.split('.') }) 2 3// will produce => 4 5{ 6 widget: "wombat", 7 foo: { 8 bar: "baz", 9 baz: { 10 quux: "qux" 11 } 12 } 13} 14
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 3/21 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
20 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More