Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
adria-forms
Advanced tools
A super simple form validation and parsing library written in TypeScript. Works both in the client and server.
npm i adria-forms
yarn add adria-forms
pnpm add adria-forms
Demo: https://adria-demo.vercel.app
import { Form } from "adria-forms";
const form = new Form().field("username", (value) => {
if (!value) throw "Please enter your username";
if (typeof value !== "string") throw "Invalid input";
if (value.length < 4) throw "Username must be at least 4 characters long";
return value;
});
const formData = new FormData(); // can be a regular object as well
const { data, errors } = await form.parse(formData);
// intellisense
const usernameError = errors?.username;
const { username } = data;
Form
field()
Creates a new field. fieldName
cannot be an existing field name, and parse
can be a synchronous or asynchronous function. The return value will be mapped to data[fieldName]
of the return type of parse()
.
const field: (
fieldName: string,
parse: (
value: null | FormDataEntryValue,
formData: Map<string, FormDataEntryValue | null>
) => MaybePromise<any>
) => Form;
new Form()
.field("username", (value) => {
if (!value)
throw {
code: 0,
message: "empty input",
};
return value; // success
})
.field("password", (_, formData) => {
const usernameField = formData.get("username"); // autocompletes username, password
const passwordField = formData.get("randomFieldName"); // TS will yell at you since the field doesn't exist yet
})
.field(
"username" // TS will yell at you since this field already exists
// ...
);
parse()
Validates and parses the form data. Will only check fields defined with .field()
. Either errors
or data
will be null
, but not both.
const parse: (formData: FormData | Record<any, any>) => Promise<{
errors: Record<string, any> | null; // <fieldName, error>
data: Record<string, any> | null; // <fieldName, parseResult>
}>;
const form = new Form()
.field("username", (val) => {
return val;
})
.field("password", (val) => {
if (invalid) throw Error;
return val;
});
const { errors, data } = await form.parse(formData);
if (errors) {
const usernameError: undefined | unknown = errors.username;
const passwordError: undefined | unknown = errors.password;
} else {
const { username, password } = data;
}
FAQs
A super simple form validation library
The npm package adria-forms receives a total of 0 weekly downloads. As such, adria-forms popularity was classified as not popular.
We found that adria-forms 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
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.