@vapurrmaid/validate
TypeScript icon, indicating that this package has built-in type declarations

0.3.6 • Public • Published

npm npm (scoped with tag) Publish to GH Pages

Validate

An incredibly simple, zero-dependency module for writing maintainable, easy-to-read, validation assertions.

NPM

Installation

npm install --save @vapurrmaid/validate

Documentation

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

Dependents (2)

Package Sidebar

Install

npm i @vapurrmaid/validate

Weekly Downloads

2

Version

0.3.6

License

MIT

Unpacked Size

16.8 kB

Total Files

9

Last publish

Collaborators

  • vapurrmaid