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

    4.1.7 • Public • Published

    Enforce - n4s

    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

    Keywords

    none

    Install

    npm i n4s

    DownloadsWeekly Downloads

    4,139

    Version

    4.1.7

    License

    MIT

    Unpacked Size

    159 kB

    Total Files

    51

    Last publish

    Collaborators

    • ealush