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

0.1.1 • Public • Published

🔍 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

Package Sidebar

Install

npm i type-checker-handler

Weekly Downloads

3

Version

0.1.1

License

MIT

Unpacked Size

14.5 kB

Total Files

24

Last publish

Collaborators

  • mohtasimalam