
Research
Malicious fezbox npm Package Steals Browser Passwords from Cookies via Innovative QR Code Steganographic Technique
A malicious package uses a QR code as steganography in an innovative technique.
@omarzion/validation
Advanced tools
A simple validation library that uses React's context library.
It can be used to wrap around basic inputs as it is, but it is recommended to integrate it into stateless components.
Upon invoking the validate function the error state is remembered for each invalid input and retested on each change for that input until a valid state is reached in which case it the error state is removed.
Requires React ^16.4.2
for old documentation see version 2 docs
For basic usage
import withValidation, { Wrapper } from '@omarzion/validation';
const submit = async controller => {
// this is where the magic happens
// if validation fails it fires up all the error messages
// and adds listeners to all the bad inputs and revalidates them
// on each change until they pass
if (await controller.validate()) {
// if validate() returns true, everything is valid
// getValues() returns an object with all your form inputs in key value form
const formData = controller.getValues();
// do whatever with your clean form data here
}
}
// withValidation provides controller prop
const ValidatedForm = ({ controller, Wrap, Long }) => (
<div>
<Wrap name='name' controller={controller} validate={v => v.length > 0}>
({ onChange, value, error, message }) => (
<input
style={{ borderColor: error ? 'red' : 'initial' }}
onChange={onChange}
value={value}
/>
)
</Wrap>
<button onClick={() => submit(controller)} />
</div>
)
export default withValidation()(ValidatedForm);
You can also map the controller (and optionably a validation function) and provide it to the withValidation function
import withValidation, { Wrapper } from '@omarzion/validation';
const submit = async controller => {
if (await controller.validate()) {
const formData = controller.getValues();
// do whatever with your clean form data here
}
}
// withValidation provides controller prop, and all registered validators
const ValidatedForm = ({ controller, Wrap, Long }) => (
<div>
<Wrap name='name' validate={v => v.length > 0}>
({ onChange, value, error, message }) => (
<input
style={{ borderColor: error ? 'red' : 'initial' }}
onChange={onChange}
value={value}
/>
)
</Wrap>
<button onClick={() => submit(controller)} />
</div>
)
const mapControllerToFields = register => {
return {
Wrap: register(Wrapper),
// make a validator that requires a string at least 10 characters long
Long: register(Wrapper, input => input.length > 9)
}
}
export default withValidation(mapControllerToFields)(ValidatedForm);
primary primitive for wrapping components that need validated
interface Wrapper {
name: string; // this will be the key returned by controller
// value of current input
// formValues = object of all inputs in current form
validate: (value, formValues) => {
boolean // validate should return whether input is valid
|| { valid: boolean, message: string} // can return message for errors
}
children: (ChildrenArguments) => React Element
}
interface ChildrenArguments {
onChange
value
error: boolean; // is there currently an error?
message: string; //error message or null
}
This is where all the magic happens, it handles:
The recommended way of getting a controller object is by wrapping
your component in withValidation()()
and a controller object will
be passed in as a prop
most use cases can be handled with this concise snippet
if (async controller.validate()) {
const formData = controller.getValues();
}
the primary validation function, returns true if the form is valid. It also deals with setting the error states on anything that isn't.
returns an object of key value pairs where the key is the name of the field and value is the user input
used to manually set an error on a field by name, good for a failed login
simply exists to accompany set
returns { valid, value, message }
resets the controller, this is good if validated form fields are going to be dynamically added and removed
FAQs
simple react validation library
The npm package @omarzion/validation receives a total of 15 weekly downloads. As such, @omarzion/validation popularity was classified as not popular.
We found that @omarzion/validation 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.
Research
A malicious package uses a QR code as steganography in an innovative technique.
Research
/Security News
Socket identified 80 fake candidates targeting engineering roles, including suspected North Korean operators, exposing the new reality of hiring as a security function.
Application Security
/Research
/Security News
Socket detected multiple compromised CrowdStrike npm packages, continuing the "Shai-Hulud" supply chain attack that has now impacted nearly 500 packages.