Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Declarative data validations.
Passable is a library for JS applications for writing validations in a way that's structured and declarative.
Inspired by the syntax of modern unit testing framework, passable validations are written as a spec or a contract, that reflects your form structure. Your validations run in production code, and you can use them in any framework (or without any framework at all).
The idea behind passable is that you can easily adopt its very familiar syntax, and transfer your knowledge from the world of testing to your form validations.
Much like most testing frameworks, Passable comes with its own assertion function, enforce, all error based assertion libraries are supported.
Since Passable is running in production environment, and accommodates different needs, some changes to the basic unit test syntax have been made, to cover the main ones quickly:
// validation.js
import passable, { enforce } from 'passable';
const validation = (data) => passable('NewUserForm', (test) => {
test('username', 'Must be at least 3 chars', () => {
enforce(data.username).longerThanOrEquals(3);
});
test('email', 'Is not a valid email address', () => {
enforce(data.email)
.isNotEmpty()
.matches(/[^@]+@[^\.]+\..+/g);
});
});
export default validation;
// myFeature.js
import validation from './validation.js';
const res = validation({
username: 'example',
email: 'email@example.com'
});
res.hasErrors() // returns whether the form has errors
res.hasErrors('username') // returns whether the 'username' field has errors
res.getErrors() // returns an object with an array of errors per field
res.getErrors('username') // returns an array of errors for the `username` field
As a general rule, Passable works similarly to unit tests in term that if your test throws an exception, it is considered to be failing. Otherwise, it is considered to be passing.
There are a few more ways to handle failures in order to ease migration, and in most cases, you can move your validation logic directly to into Passable with only a few adjustments.
For example, if you use a different assertion libraries such as chai
(expect) or v8n
, you can simply use it instead of enforce, and it should work straight out of the box.
FAQs
Isomorphic Data Model Validations
The npm package passable receives a total of 7,961 weekly downloads. As such, passable popularity was classified as popular.
We found that passable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.