UNPKG

type-checker-handler

Version:

An advanced Type Checker that checks and handles type for the param name on your function.

97 lines (66 loc) 1.7 kB
# 🔍 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: ```sh npm install type-checker-handler ``` Yarn: ```sh yarn add type-checker-handler ``` ## 📝 How to use Using **Type Checker** is very easy Only 1-2 lines code Example usage (TypeScript): ```ts 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): ```js 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:** ```ts typeCheck({ paramName: msg, expectedType: JsTypes.String }); ``` And ```js typeCheckJs({ paramName: msg, paramType: JsTypes.String, expectedType: JsTypes.String, }); ``` It is same for both TypeScript and JavaScript