@aaronburt/typeguard-js
v1.0.0
Published
A simple library for checking data types in JavaScript
Downloads
2
Maintainers
Readme
Input Type Checker
This module provides a set of functions to determine the type of the given input. The following functions are available:
isNumber(): returns true if the input is a number, false otherwise.
isString(): returns true if the input is a string, false otherwise.
isBoolean(): returns true if the input is a boolean, false otherwise.
isNull(): returns true if the input is null, false otherwise.
isUndefined(): returns true if the input is undefined, false otherwise.
isSymbol(): returns true if the input is a symbol, false otherwise.
isJSONObject(): returns true if the input is a valid JSON object, false otherwise.
Usage
To use this module, import it and call the desired function with the input as a parameter.
import inputTypeChecker from './inputTypeChecker.js';
const input = 'hello world';
const checker = inputTypeChecker(input);
console.log(checker.isString()); // true
console.log(checker.isNumber()); // false
console.log(checker.isBoolean()); // false
console.log(checker.isNull()); // false
console.log(checker.isUndefined()); // false
console.log(checker.isSymbol()); // false
console.log(checker.isJSONObject()); // false
Install
You need to install typescript and run tsc
to generate the ./dist/ folder
License
This project is licensed under the MIT License - see the LICENSE.md file for details.