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.
extensible-validator
Advanced tools
Typescript-friendly and extensible object and value validation. It looks mostly like joi, but is more extensible and auto-complete friendly.
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
The npm package extensible-validator receives a total of 0 weekly downloads. As such, extensible-validator popularity was classified as not popular.
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
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.