Skip to content

Repository files navigation

This project is now called Checkard.js.

Thus it has been transferred to @dwtechs/checkard.

Please update your project dependencies as this one will not be updated anymore.

License: MITnpm versionlast version release dateJest:coverageminified 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

Browsers

  • android: 2.2,
  • chrome: 34,
  • edge: 12,
  • firefox: 11,
  • ie: 9,
  • ios: 4.2,
  • opera: 28,
  • safari: 5.1,
  • samsung: 4

Those are the oldest targeted versions. The library should work properly on older devices but we do not support it officially.

Installation

$ npm i @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

constch=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

<scriptsrc="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

Types

Comparator='='|'<'|'>'|'<='|'>=';

Primitive

isBoolean(bool: any): boolean{}isString(string: any,emptyCheck: boolean=false): boolean{}// If typeCheck = false values like '4', '0', '8e4', '+true', '0x44' return trueisNumber(number: any,typeCheck: boolean=true): boolean{}isSymbol(sym: any): boolean{}

Structural

isFunction(func: any): boolean{}isObject(obj: any,emptyCheck: boolean=false): boolean{}//Check whether val is null or undefinedisNil(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{}

Valid number

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

String

isStringOfLength(string: any,min: number=0,max: number=999999999): boolean{}isJson(string: any): boolean{}isRegex(regex: any,typeCheck: boolean=true): boolean{}isEmail(email: any): boolean{}isIpAddress(ipAddress: any): boolean{}isJWT(t: 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,min?: number|null,max?: number|null): boolean{}

Date

isDate(date: any): boolean{}isValidDate(date: any,min: Date=newDate('1/1/1900'),max: Date=newDate('1/1/2200')): boolean{}isTimestamp(number: any,typeCheck: boolean=true): 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,typeCheck: boolean=true): boolean{}

Array

// Check if 'array' is an array and optionally if it is of length =, <, >, <= or >= than 'length'isArray(array: any,comparator?: Comparator|null,length?: number|null): boolean{}

example :

letar=['dog','cat','bird'];if(isArray(array)){// check if ar is an array}if(isArray(array,'=',2)){// check if ar is an array of length 2}if(isArray(array,'>=',1)){// check if ar is an array of length greater than or equal to 1}

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

PurposeChoiceMotivation
repositoryGithubhosting for software development version control using Git
package managernpmdefault node.js package manager
languageTypeScriptstatic type checking along with the latest ECMAScript features
module bundlerRollup.jsadvanced module bundler for ES6 modules
unit testingJestdelightful testing with a focus on simplicity

About

This library is no longer maintained. Please use @DWTechs/Checkard.js instead.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages