Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
ls-service-form2json
Advanced tools
Litespeed.js service component that converts an HTML form element to a valid JSON object.
Litespeed.js service component that converts an HTML form element to a valid JSON object.
This package is wrapped as a Litespeed.js component. To use it, you need to init a new Litespeed.js project or use an exisiting Litespeed.js project. To learn more about Litespeed.js Javascript web framework got to the official repository.
Install with NPM:
npm install ls-service-form2json
Install with CDN:
<script src="https://cdn.jsdelivr.net/npm/ls-service-form2json"></script>
The form2json service uses each form element name attribute as a key for the output JSON object and the element value as the JSON key value.
The form2json service uses a FIELDSET tag to wrap a set of primitives as an object. When multiple form elements have the same name attribute the will be joined into an array. If you wish to force an array casting for single elements who have a unique name attribute, add the data-cast-to="array" attribute to the required form element.
The form2json service is trying to cast HTML form elements to their most suitable var types. For example, number or range input elements will be converted to into integers, while text or search input elements will be converted to strings. To force a specific type use the data-cast-to="array" on your HTML element. The data-cast-to attribute accepts these values: string, int, integer, bool, boolean, array, and JSON. The JSON type converts a resulting form object (FIELDSET tag) to a JSON string.
Checkbox elements are automatically cast to an array list of checked values.
This basic form:
<form id="unique">
<input type="text" name="title" value="Hello World!" />
<input type="text" name="firstname" value="Eldad" />
<input type="text" name="lastname" value="Fux" />
</form>
let form = document.getElementById('unique');
let form2json = window.ls.container.get('form2json');
return form2json.toJson(form);
Will result to this JSON:
{
"title": "Hello World!",
"firstname": "Eldad",
"lastname": "Fux",
}
This form:
<form id="unique">
<input type="text" name="title" value="Coding Languages" />
<fieldset name="language">
<input type="text" name="name" value="PHP" />
<input type="text" name="link" value="https://www.php.net/" />
</fieldset>
<fieldset name="language">
<input type="text" name="name" value="NodeJS" />
<input type="text" name="link" value="https://nodejs.org/en/" />
</fieldset>
<fieldset name="language">
<input type="text" name="name" value="Ruby" />
<input type="text" name="link" value="https://www.ruby-lang.org/en/" />
</fieldset>
</form>
let form = document.getElementById('unique');
let form2json = window.ls.container.get('form2json');
return form2json.toJson(form);
Will result to this JSON including a list of objects:
{
"title": "Coding Languages",
"language": [
{ "name": "PHP", "link": "https://www.php.net/"},
{ "name": "NodeJS", "link": "https://nodejs.org/en/"},
{ "name": "Ruby", "link": "https://www.ruby-lang.org/en/"}
]
}
For more examples visit our jest test file
All code contributions - including those of people having commit access - must go through a pull request and approved by a core developer before being merged. This is to ensure proper review of all the code.
Fork the project, create a feature branch, and send us a pull request.
For security issues, please email security@appwrite.io instead of posting a public issue in GitHub.
The MIT License (MIT) http://www.opensource.org/licenses/mit-license.php
FAQs
Litespeed.js service component that converts an HTML form element to a valid JSON object.
The npm package ls-service-form2json receives a total of 2 weekly downloads. As such, ls-service-form2json popularity was classified as not popular.
We found that ls-service-form2json demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.