Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
lakmus-michaelmyers
Advanced tools
Fluent validation in TypeScript.
Inspired by .NET FluentValidation
export class Person {
public id: number;
public name: string;
public address: Address;
public phoneNumbers: PhoneNumber[];
public hasDiscount: boolean;
public discountValue: number;
}
export class Address {
public country: string;
public city: string;
public street: string;
public houseNumber: string;
}
export class PhoneNumber {
public country: string;
public code: string;
public number: string;
}
export class PersonValidator extends Validator<Person> {
constructor() {
super();
// not null & max length;
this.ruleFor(x => x.name)
.notNull()
.maxLength(100);
// nested objection validation;
this.ruleFor(x => x.address)
.notNull()
.setValidator(new AddressValidator());
// collection validation;
this.ruleFor(x => x.phoneNumbers)
.notNull()
.setCollectionValidator(new PhoneNumberValidator());
this.when(x => x.hasDiscount, () => {
this.ruleFor(x => x.discountValue)
.notNull();
});
}
}
export class AddressValidator extends Validator<Address> {
constructor() {
super();
this.ruleFor(x => x.city)
.notNull().maxLength(50);
this.ruleFor(x => x.street)
.notNull().maxLength(50);
}
}
export class PhoneNumberValidator extends Validator<PhoneNumber> {
constructor() {
super();
this.ruleFor(x => x.country)
.notNull().maxLength(3);
this.ruleFor(x => x.code)
.notNull().maxLength(5);
// predicate and custom error message;
this.ruleFor(x => x.number)
.notNull().maxLength(7)
.must((number, phoneNumber) => (phoneNumber.code || "").length + (phoneNumber.country || "").length + (phoneNumber.number || "").length == 11)
.withMessage("Please enter a valid phone number.");
}
}
// set custom property name resolver: discountValue -> Discount Value
ValidatorOptions.propertyNameResolver = ApStyleTitleCasePropertyNameResolver;
// initialize object to validate;
var person = new Person();
// create validator;
var validator = new PersonValidator();
// or get it from factory (recommended)
validator = ValidatorFactory.getValidator(PersonValidator);
// validate;
var result = validator.validate(person);
// process result;
if (result.isValid) {
console.log("Is valid.");
}
else {
console.log(result.errors.map(x => x.errorMessage).join("\n"));
}
MIT
FAQs
Fluent validation.
The npm package lakmus-michaelmyers receives a total of 2 weekly downloads. As such, lakmus-michaelmyers popularity was classified as not popular.
We found that lakmus-michaelmyers 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
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.