
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
@avinlab/form
Advanced tools
npm install @avinlab/form
Create a form and manage its values:
import { createForm } from '@avinlab/form';
// Create a form with initial values
const initialValues = { name: 'John', age: 30 };
const form = createForm(initialValues);
// Subscribe to updates
const handleUpdateForm = (newValues, prevValues) => {
console.log('Form updated', { newValues, prevValues });
};
form.onUpdate(handleUpdateForm);
const handleUpdateAgeField = (newValue, oldValue) => {
console.log('Field "age" updated', { newValue, oldValue });
};
form.onUpdateField('age', handleUpdateAgeField);
// Set form values
form.setValue('name', 'Jane');
form.setValue('age', 31);
// Set all form values at once
form.setValues({ name: 'Jane', age: 31 });
// Unsubscribe from updates
form.offUpdate(handleUpdateForm);
form.offUpdateField('age', handleUpdateAgeField);
Form validation management:
import { createForm, createFormValidation } from '@avinlab/form';
const initialValues = { name: 'John', age: 30 };
const form = createForm(initialValues);
const formValidation = createFormValidation(form, (values) => {
const errors = {};
if (!values.name) {
errors.name = 'Name is required';
}
if (values.age && values.age < 18) {
errors.age = 'Must be at least 18';
}
return errors;
});
console.log(formValidation.errors); // Output: {}
console.log(formValidation.isValid); // Output: true
// Set an incorrect value for the age field
form.setValue('age', 15);
console.log(formValidation.errors); // Output: {age: 'Must be at least 18'}
console.log(formValidation.isValid); // Output: false
// Subscribe to validation changes
const handler = (errors) => {
console.log(errors);
};
formValidation.onValidate(handler);
// Unsubscribe from validation updates
formValidation.offValidate(handler);
// Validation is triggered automatically when the form values change,
// but you can also initiate validation manually
formValidation.validate();
FAQs
## Install
The npm package @avinlab/form receives a total of 0 weekly downloads. As such, @avinlab/form popularity was classified as not popular.
We found that @avinlab/form demonstrated a healthy version release cadence and project activity because the last version was released less than 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
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.