Validate
An incredibly simple, zero-dependency module for writing maintainable, easy-to-read, validation assertions.
NPM
-
@vapurrmaid/validate
is located at https://www.npmjs.com/package/@vapurrmaid/validate
Installation
npm install --save @vapurrmaid/validate
Documentation
-
Validate
API documentation generated bytypedoc
is located at https://vapurrmaid.ca/Validate
Example Usage
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;
}
}
Why Would I Use This
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
- Contributing contains a very short basic list of requirements and notices for contributing
- Wiki contains all relevant documentation for development and releases
Inspiration
- The Java package org.apache.commons.lang3.Validate
- The native NodeJs module
assert
- Matchers & BDD-style assertions used in
Jest
andchai