Gigapipe
Open source observability warehouse on ClickHouse. Send logs, metrics, traces and profiles with the agents you already run, and query them in Grafana with no plugins. Flat pricing, your infrastructure
翻译准备中
Parse browser forms into structured JavaScript objects. Six adapters — React hooks, vanilla DOM, jQuery, FormData, and more. One coherent API.
翻译准备中
开发工具TypeScript · CSSGitHub @maxatwork自行安装运营者未确认
试用过了吗? 点一下就好,无需登录。
制作者的介绍仅有上面的一句话。 更多详情请阅读仓库 README。 仓库 README ↗
正在加载完整 README。
查看完整 README ↗🚀 form2js is back — modernized and actively maintained.
Originally created in 2010, now rewritten for modern JavaScript, TypeScript, ESM, React, and modular usage.
Legacy version is available in the legacy branch.
Migrating from legacy form2js? Start with the migration guide.
A small family of packages for turning form-shaped data into objects, and objects back into forms.
It is not a serializer, not an ORM, and not a new religion. It just does this one job, does it reliably, and leaves before anyone starts a committee about it.
form2js and jquery.toObject usage to the current package family.If you are moving from the archived single-package version, start with the migration guide.
Quick package map:
form2js(...) usage -> @form2js/dom$("#form").toObject() usage -> @form2js/jqueryFormData parsing -> @form2js/form-data@form2js/react@form2js/js2formThe current project keeps the naming rules and core parsing model, but splits the old browser-era API into environment-specific packages.
| Package | npm | Purpose | Module | Standalone | Node.js |
|---|---|---|---|---|---|
@form2js/react | React submit hook with parsing/validation state | Yes | No | Browser-focused | |
@form2js/dom | Extract DOM fields to object (formToObject, form2js) | Yes | Yes | With DOM shim (jsdom) | |
@form2js/form-data | Convert FormData/entries to object | Yes | No | Yes | |
@form2js/js2form | Populate DOM fields from object (objectToForm, js2form) | Yes | No | With DOM shim (jsdom) | |
@form2js/core | Path parsing and object transformation engine | Yes | No | Yes | |
Install only what you need:
npm install @form2js/react react
npm install @form2js/dom
npm install @form2js/form-data
npm install @form2js/js2form
npm install @form2js/core
npm install @form2js/jquery jquery
For browser standalone usage, use script builds where available:
@form2js/dom: dist/standalone.global.js@form2js/jquery: dist/standalone.global.js@form2js/domHTML used in examples:
<form id="profileForm">
<input name="person.name.first" value="Esme" />
<input name="person.name.last" value="Weatherwax" />
<label
><input type="checkbox" name="person.tags[]" value="witch" checked />
witch</label
>
</form>
Module:
import { formToObject } from "@form2js/dom";
const result = formToObject(document.getElementById("profileForm"));
// => { person: { name: { first: "Esme", last: "Weatherwax" }, tags: ["witch"] } }
Standalone:
<script src="https://unpkg.com/@form2js/dom/dist/standalone.global.js"></script>
<script>
const result = formToObject(document.getElementById("profileForm"));
// or form2js(...)
</script>
@form2js/form-dataModule (browser or Node 18+):
import { formDataToObject } from "@form2js/form-data";
const fd = new FormData(formElement);
const result = formDataToObject(fd);
Node.js note:
FormData.import { entriesToObject } from "@form2js/form-data";
const result = entriesToObject([
["person.name.first", "Sam"],
["person.roles[]", "captain"],
]);
// => { person: { name: { first: "Sam" }, roles: ["captain"] } }
With schema validation (works with Zod or any { parse(unknown) } schema):
import { z } from "zod";
import { formDataToObject } from "@form2js/form-data";
const PersonSchema = z.object({
person: z.object({
age: z.coerce.number().int().min(0)
})
});
const result = formDataToObject([["person.age", "42"]], {
schema: PersonSchema
});
// => { person: { age: 42 } }
Standalone:
@form2js/reactModule:
import { z } from "zod";
import { useForm2js } from "@form2js/react";
const FormDataSchema = z.object({
person: z.object({
name: z.object({
first: z.string().min(1)
})
})
});
export function ProfileForm(): React.JSX.Element {
const { onSubmit, isSubmitting, isError, error, isSuccess, reset } = useForm2js(
async (data) => {
// data is inferred from schema when schema is provided
await sendFormData(data);
},
{
schema: FormDataSchema
}
);
return (
<form
onSubmit={(event) => {
void onSubmit(event);
}}
>
<input name="person.name.first" defaultValue="Sam" />
<button type="submit" disabled={isSubmitting}>
{isSubmitting ? "Saving..." : "Save"}
</button>
{isError ? <p>{String(error)}</p> : null}
{isSuccess ? <p>Saved</p> : null}
<button type="button" onClick={reset}>
Reset state
</button>
</form>
);
}
@form2js/jqueryHTML used in examples:
<form id="profileForm">
<input name="person.name.first" value="Sam" />
<input name="person.name.last" value="Vimes" />
</form>
Module:
import $ from "jquery";
import { installToObjectPlugin } from "@form2js/jquery";
installToObjectPlugin($);
const data = $("#profileForm").toObject({ mode: "first" });
// => { person: { name: { first: "Sam", last: "Vimes" } } }
Standalone:
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://unpkg.com/@form2js/jquery/dist/standalone.global.js"></script>
<script>
const data = $("#profileForm").toObject({ mode: "combine" });
</script>
@form2js/js2formHTML used in examples (before calling objectToForm):
<form id="profileForm">
<input name="person.name.first" />
<input name="person.name.last" />
</form>
Module:
import { objectToForm } from "@form2js/js2form";
objectToForm(document.getElementById("profileForm"), {
person: { name: { first: "Tiffany", last: "Aching" } },
});
// fields are now populated in the form
Standalone:
@form2js/coreModule:
import { entriesToObject, objectToEntries } from "@form2js/core";
const data = entriesToObject([
{ key: "person.name.first", value: "Vimes" },
{ key: "person.tags[]", value: "watch" },
]);
const pairs = objectToEntries(data);
Node.js:
Standalone:
Compatibility with the old project is intentional.
person.name.first).items[], items[5].name).rails[field][value]).__proto__, prototype, constructor) are rejected by default.These boundaries are intentional and are used for issue triage.
items[5], items[8] -> items[0], items[1]).formToObject reads successful form control values, not option labels. Disabled controls (including disabled fieldset descendants) and button-like inputs are excluded unless you explicitly opt in to disabled values.extractPairs/formToObject support nodeCallback; return SKIP_NODE to exclude a node entirely, or { name|key, value } to inject a custom entry.allowUnsafePathSegments: true only with trusted inputs.objectToForm supports nodeCallback; returning false skips the default assignment for that node.objectToForm sets form control state and values; it does not dispatch synthetic change or input events.key/val fields into arbitrary object keys) is application logic.FormData and @form2js/form-data.npm ci
npm run lint
npm run typecheck
npm run test
npm run build
npm run pack:dry-run
npm run docs
npm run docs:build
The homepage includes the unified playground for @form2js/react, @form2js/dom, @form2js/jquery, @form2js/js2form, @form2js/core, and @form2js/form-data.
The published docs site is deployed by .github/workflows/pages.yml.
master that touch apps/docs/**, docs/**, packages/**, .github/workflows/pages.yml, package.json, package-lock.json, turbo.json, or tsconfig.base.json, plus manual workflow_dispatch.apps/docs/dist.https://maxatwork.github.io/form2js/.In repository settings, set Pages source to GitHub Actions once, and then the workflow handles updates.
npm run changeset) for user-visible changes.Please include:
node -v, browser/version if relevant).@form2js/* packages are versioned in lockstep.Default scope is @form2js/*.
If you need to publish under another scope:
npm run scope:rewrite -- --scope @your-scope --dry-run
npm run scope:rewrite -- --scope @your-scope
This rewrites package names, internal dependencies, and import references.
MIT, see LICENSE.
@form2js/jqueryjQuery plugin adapter ($.fn.toObject) |
| Yes |
| Yes |
| Browser-focused |