@dwtechs/checkhard

is an open source dynamic type checking library for Javascript and Node.js to test if a given variable is what it is supposed to be.

Usage no npm install needed!

<script type="module">
  import dwtechsCheckhard from 'https://cdn.skypack.dev/@dwtechs/checkhard';
</script>

README

License: MIT npm version last version release date Jest:coverage minified size

Synopsis

CheckHard.js is an open source dynamic type checking library for Javascript and Node.js to test if a given variable is what it is supposed to be.
Function, object, ascii, boolean, integer, string, json, email...\

  • No dependency
  • Very lightweight
  • Thoroughly tested
  • Works in browsers and Node.js
  • Old browsers support (IE9)

Installation

npm

$ npm i @dwtechs/checkhard

Yarn

$ yarn add @dwtechs/checkhard

Usage

ES6 / TypeScript

import { isFunction, isArray } from "@dwtechs/checkhard";

if (isFunction(variable)) {
  //variable is a function
}

if (!isArray(variable, 2)) {
  //variable is not an array of length 2
}

CommonJS

const ch = require("@dwtechs/checkhard/dist/ch.cjs");

if (ch.isFunction(variable)) {
  //variable is a function
}

if (!ch.isArray(variable, 2)) {
  //variable is not an array of length 2
}

IIFE

<script src="node-modules/@dwtechs/checkhard/dist/ch.iife.min.js"></script>
if (CH.isFunction(variable)) {
  //variable is a function
}

if (!CH.isArray(variable, 2)) {
  //variable is not an array of length 2
}

API Reference

Primitive


isBoolean(bool: any): boolean {}

isString(string: any): boolean {}

// Check if a variable is a numeric value,
// If typeCheck = false values like '8e4', '+true', '0x44' return true
isNumber(number: any, typeCheck: boolean = true): boolean {}

isValidNumber(number: any, 
              min: number = -999999999, 
              max: number = 999999999, 
              typeCheck: boolean = true ): boolean {}

isSymbol(sym: any): boolean {}

Structural


isFunction(func: any): boolean {}

isObject(obj: any): boolean {}

//Check whether val is null or undefined
isNil(val: any): boolean {}

Number


isInteger(number: any, typeCheck: boolean = true): boolean {}

isFloat(number: any, typeCheck: boolean = true): boolean {}

isEven(number: any, typeCheck: boolean = true): boolean {}

isOdd(number: any, typeCheck: boolean = true): boolean {}

isOrigin(number: any, typeCheck: boolean = true): boolean {}

isPositive(number: any, typeCheck: boolean = true): boolean {}

isNegative(number: any, typeCheck: boolean = true): boolean {}

isPowerOfTwo(number: any, typeCheck: boolean = true): boolean {}

isAscii(code: any, extended: boolean = false): boolean {}

String


isJson(string: any): boolean {}

isRegex(regex: any, typeCheck: boolean = true): boolean {}

isEmail(email: any): boolean {}

isIpAddress(ipAddress: any): boolean {}

isSlug(slug: any): boolean {}

isHexadecimal(string: any): boolean {}

containsUpperCase(string: any): boolean {}

containsLowerCase(string: any): boolean {}

containsSpecialCharacter(string: any): boolean {}

containsNumber(string: any): boolean {}

Date


isDate(date: any): boolean {}

isValidDate(date: any, min: Date = new Date('1/1/1900'), max: Date = new Date('1/1/2200')): boolean {}

isTimestamp(number: any): boolean {}

// default min = 1/1/1900 (month/day/year)
// default max = 1/1/2200 (month/day/year)
isValidTimestamp(number: any, min: number = -2208989361000, max: number = 7258114800000): boolean {}

Array


// Check if 'array' is an array and if it is of length 'length'
isArray(array: any, length?: number|null): boolean {}

Html


isHtmlElement(htmlElement: any): boolean {}

isHtmlEventAttribute(htmlEventAttribute: any): boolean {}

isNode(node: any): boolean {}

Contributors

CheckHard.js is still in development and we would be glad to get all the help you can provide. To contribute please read contributor.md for detailed installation guide.

Stack

Purpose Choice Motivation
repository Github hosting for software development version control using Git
package manager npm default node.js package manager
language TypeScript static type checking along with the latest ECMAScript features
module bundler Rollup.js advanced module bundler for ES6 modules
unit testing Jest delightful testing with a focus on simplicity