n4s
TypeScript icon, indicating that this package has built-in type declarations

5.0.23 • Public • Published

Enforce - n4s

Join Discord Version Downloads bundlephobia Status

Enforce is a validations assertions library. It provides rules that you can test your data against.

By default, enforce throws an error when your validations fail. These errors should be caught by a validation testing framework such as Vest.

You can extend Enforce per need, and you can add your custom validation rules in your app.

import { enforce } from 'n4s';

enforce(4).isNumber();
// passes

enforce(4).isNumber().greaterThan(2);
// passes

enforce(4)
  .lessThan(2) // throws an error, will not carry on to the next rule
  .greaterThan(3);

Installation

npm i n4s

Non throwing validations

This functionality replaces the no-longer supported ensure export, as it performs the same functionality with better performance.

If you wish to use enforce's functionality safely with a boolean return interface, you can use its lazy validation interface:

enforce.isArray().longerThan(3).test([1, 2, 3]);

Read the docs

Package Sidebar

Install

npm i n4s

Weekly Downloads

8,381

Version

5.0.23

License

MIT

Unpacked Size

580 kB

Total Files

118

Last publish

Collaborators

  • ealush