0.1.1 • Published 2 years ago

type-checker-handler v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

🔍 TypeChecker

An advanced Type Checker that checks and handles type for the param name on your function built to make nodejs module creating easy. Both TypeScript and JavaScript.

🚀 Features

  • Easy to code
  • Zero dependencies
  • Light weight module
  • Make type-checking easy
  • Error handler

💻 Installation

NPM:

npm install type-checker-handler

Yarn:

yarn add type-checker-handler

📝 How to use

Using Type Checker is very easy Only 1-2 lines code

Example usage (TypeScript):

import { JsTypes, typeCheck } from "type-checker-handler";

const aFunction = (msg: string, ...optional: any[]) => {
  typeCheck({ paramName: msg, expectedType: JsTypes.String });
  let output = msg;

  if (optional.length > 0) {
    output += optional.join(" ");
  }

  return output;
};

export { aFunction };

If the user provided parameter type is not same as the function's required type it will throw a `TypeError`

Example Usage (JavaScript):

const { JsTypes, typeCheckJs } = require("type-checker-handler");

const aFunction = (msg, ...optional) => {
  typeCheckJs({
    paramName: msg,
    paramType: JsTypes.String,
    expectedType: JsTypes.String,
  });
  let output = msg;

  if (optional.length > 0) {
    output += optional.join(" ");
  }

  return output;
};

export { aFunction };

Not 1-2 line(s) of code?

The code given in the example is full code.

The exact type-checking code is:

typeCheck({ paramName: msg, expectedType: JsTypes.String });

And

typeCheckJs({
  paramName: msg,
  paramType: JsTypes.String,
  expectedType: JsTypes.String,
});

It is same for both TypeScript and JavaScript