Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
extensible-validator
Advanced tools
Typescript-friendly and extensible object and value validation
Typescript-friendly and extensible object and value validation.
Also, unlike like other libraries where validate
throws an error, I just return an array of errors, which could be empty. Throwing an error in the case of bad input from a function which exists to consider the case of bad input is ugly as hell.
I also separate validating and "casting" the input to a desired output format, because they're two separate operations.
Install:
$ npm install --save extensible-validator
Import, then define and use a schema:
import { object, string, number } from 'extensible-validator';
let validator = object.keys({
name: string.required(),
age: number.integer(),
});
let person = { name: 'Bob', age: 32 };
console.log(validator.validate(person));
// []
let notAPerson = { age: "what's my age again?" };
console.log(validator.validate(notAPerson));
// [{message: 'required', path: 'name'}, {message: 'must be a number', path: 'age'}]
If you want to extend the validator functionality, you can either add tests to existing types:
const objectId = string.addTest(value => ObjectId.isValid(value));
const person = object.keys({
_id: objectId.required(),
name: string.required(),
});
Or you can define a new schema class:
class ObjectIdSchema extends Schema<ObjectId> {
constructor() {
super({ type: 'must be an ObjectId' }, value => ObjectId.isValid(value));
}
cast(value: any) {
return value instanceof ObjectId ? value : new ObjectId(value);
}
}
The latter gives you more control, and the ability to override the type test and the cast
method.
TODO
FAQs
Typescript-friendly and extensible object and value validation
We found that extensible-validator 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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
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.