ccax
v1.0.3
Published
This library will help to assert the parameters, instances, classes, functions, primitive/non-primitive types
Downloads
34
Maintainers
Readme
CCAX
Overview
This project is to utilize when we want to assert some params, it can be string, number or any instance of any class. The motivation behind this is to avoid if-else chains just to validate the parameters. see https://stackoverflow.com/q/73795540/2961427 for more details.
Use Case:
- We can use this library to safeguard any methods before actual logic execution
- It can reduce
if-else
chain anywhere in the code by pre-asserting the required/optional parameters.
How to Use
First, you will have to install the
CCAX
npm i ccax
You will have to require the
CCAX
import ccax from 'ccax'; // Start using it. ccax.assertString('String Value'); // Will not throw any error, as it's a valid string
or if you are using node with require, use the below example"
const ccax = require('ccax').default; // Start using it. ccax.assertString(true, 'name'); // Throws the Error: `Param name must be a String` because value is boolean
You can use try catch for better error handling.