An incredibly simple, zero-dependency module for writing maintainable, easy-to-read, validation assertions.
@vapurrmaid/validate
is located at https://www.npmjs.com/package/@vapurrmaid/validate
npm install --save @vapurrmaid/validate
Validate
API documentation generated bytypedoc
is located at https://vapurrmaid.ca/Validate
Without ❌
class PositiveNumber {
public readonly value: number;
constructor(n: number) {
if (n <= 0) {
throw new Error(`n must be greater than 0`);
}
this.value = n;
}
}
With ✔️
import { Validate } from "@vapurrmaid/validate";
class PositiveNumber {
public readonly value: number;
constructor(n: number) {
Validate.n(n).isGreaterThan(0, `n must be greater than 0`);
this.value = i;
}
}
Usage of Validate
is an opinionated, stylistic preference. Other options
exists and should be explored. The unifying goal of these libraries is to
improve logic expression and readability of source code. If the library is
complicating code, then use something else!
- Contributing contains a very short basic list of requirements and notices for contributing
- Wiki contains all relevant documentation for development and releases
- The Java package org.apache.commons.lang3.Validate
- The native NodeJs module
assert
- Matchers & BDD-style assertions used in
Jest
andchai