Socket
Socket
Sign inDemoInstall

n4s

Package Overview
Dependencies
2
Maintainers
1
Versions
152
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    n4s

Assertion library for form validations


Version published
Weekly downloads
8.4K
decreased by-15.65%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 03 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc