CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-is-js

Micro check library providing comprehensive type checking and validation operations across different JavaScript environments

Pending
Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Pending

The risk profile of this skill

Overview
Eval results
Files

type-checking.mddocs/

Type Checking

Core type validation functions for JavaScript primitives and objects. Essential for runtime type safety and input validation.

Capabilities

Basic Type Detection

Arguments Check

Checks if the given value is an Arguments object.

/**
 * Checks if the given value type is arguments
 * @param value - Value to check
 * @returns True if value is Arguments object
 * Interfaces: not, all, any
 */
function arguments(value: any): boolean;

Usage Example:

function getArguments() {
  return arguments;
}
const args = getArguments('test');

is.arguments(args);        // true
is.not.arguments({foo: 'bar'}); // true
is.all.arguments(args, 'bar');  // false
is.any.arguments(['foo'], args); // true

Array Check

Checks if the given value is an Array.

/**
 * Checks if the given value type is array
 * @param value - Value to check
 * @returns True if value is Array
 * Interfaces: not, all, any
 */
function array(value: any): boolean;

Usage Example:

is.array(['foo', 'bar', 'baz']); // true
is.not.array({foo: 'bar'});      // true
is.all.array(['foo'], 'bar');    // false
is.any.array(['foo'], 'bar');    // true

Boolean Check

Checks if the given value is a Boolean.

/**
 * Checks if the given value type is boolean
 * @param value - Value to check
 * @returns True if value is Boolean
 * Interfaces: not, all, any
 */
function boolean(value: any): boolean;

Usage Example:

is.boolean(true);             // true
is.not.boolean({foo: 'bar'}); // true
is.all.boolean(true, 'bar');  // false
is.any.boolean(true, 'bar');  // true

Character Check

Checks if the given value is a single character string.

/**
 * Checks if the given value type is char
 * @param value - Value to check
 * @returns True if value is single character string
 * Interfaces: not, all, any
 */
function char(value: any): boolean;

Usage Example:

is.char('f');              // true
is.not.char(['foo']);      // true
is.all.char('f', 1);       // false
is.any.char('f', 2);       // true
is.all.char(['f', 'o', 'o']); // true

Date Check

Checks if the given value is a Date object.

/**
 * Checks if the given value type is date
 * @param value - Value to check
 * @returns True if value is Date object
 * Interfaces: not, all, any
 */
function date(value: any): boolean;

Usage Example:

is.date(new Date());          // true
is.not.date({foo: 'bar'});    // true
is.all.date(new Date(), 'bar'); // false
is.any.date(new Date(), 'bar'); // true

Error Check

Checks if the given value is an Error object.

/**
 * Checks if the given value type is error
 * @param value - Value to check
 * @returns True if value is Error object
 * Interfaces: not, all, any
 */
function error(value: any): boolean;

Usage Example:

is.error(new Error());        // true
is.not.error({foo: 'bar'});   // true
is.all.error(new Error(), 'bar'); // false
is.any.error(new Error(), 'bar'); // true

Function Check

Checks if the given value is a Function.

/**
 * Checks if the given value type is function
 * @param value - Value to check
 * @returns True if value is Function
 * Interfaces: not, all, any
 */
function function(value: any): boolean;

Usage Example:

is.function(toString);         // true
is.not.function({foo: 'bar'}); // true
is.all.function(toString, 'bar'); // false
is.any.function(toString, 'bar'); // true

NaN Check

Checks if the given value is NaN.

/**
 * Checks if the given value type is NaN
 * @param value - Value to check
 * @returns True if value is NaN
 * Interfaces: not, all, any
 */
function nan(value: any): boolean;

Usage Example:

is.nan(NaN);           // true
is.not.nan(42);        // true
is.all.nan(NaN, 1);    // false
is.any.nan(NaN, 2);    // true

Null Check

Checks if the given value is null.

/**
 * Checks if the given value type is null
 * @param value - Value to check
 * @returns True if value is null
 * Interfaces: not, all, any
 */
function null(value: any): boolean;

Usage Example:

is.null(null);         // true
is.not.null(42);       // true
is.all.null(null, 1);  // false
is.any.null(null, 2);  // true

Number Check

Checks if the given value is a Number (excluding NaN).

/**
 * Checks if the given value type is number
 * @param value - Value to check
 * @returns True if value is Number and not NaN
 * Interfaces: not, all, any
 */
function number(value: any): boolean;

Usage Example:

is.number(42);            // true
is.number(NaN);           // false
is.not.number('42');      // true
is.all.number('foo', 1);  // false
is.any.number({}, 2);     // true

Object Check

Checks if the given value is an Object.

/**
 * Checks if the given value type is object
 * @param value - Value to check
 * @returns True if value is Object (including functions)
 * Interfaces: not, all, any
 */
function object(value: any): boolean;

Usage Example:

is.object({foo: 'bar'});     // true
is.object(toString);         // true (functions are objects)
is.not.object('foo');        // true
is.all.object({}, 1);        // false
is.any.object({}, 2);        // true

RegExp Check

Checks if the given value is a RegExp.

/**
 * Checks if the given value type is RegExp
 * @param value - Value to check
 * @returns True if value is RegExp
 * Interfaces: not, all, any
 */
function regexp(value: any): boolean;

Usage Example:

is.regexp(/test/);              // true
is.not.regexp(['foo']);         // true
is.all.regexp(/test/, 1);       // false
is.any.regexp(new RegExp('ab+c'), 2); // true

String Check

Checks if the given value is a String.

/**
 * Checks if the given value type is string
 * @param value - Value to check
 * @returns True if value is String
 * Interfaces: not, all, any
 */
function string(value: any): boolean;

Usage Example:

is.string('foo');            // true
is.not.string(['foo']);      // true
is.all.string('foo', 1);     // false
is.any.string('foo', 2);     // true

Undefined Check

Checks if the given value is undefined.

/**
 * Checks if the given value type is undefined
 * @param value - Value to check
 * @returns True if value is undefined
 * Interfaces: not, all, any
 */
function undefined(value: any): boolean;

Usage Example:

is.undefined(undefined);     // true
is.not.undefined(null);      // true
is.all.undefined(undefined, 1); // false
is.any.undefined(undefined, 2); // true

Advanced Type Checks

DOM Node Check

Checks if the given object is a DOM node.

/**
 * Checks if the given object is a dom node
 * @param object - Object to check
 * @returns True if object is DOM node
 * Interfaces: not, all, any
 */
function domNode(object: any): boolean;

Usage Example:

const obj = document.createElement('div');
is.domNode(obj);                // true
is.domNode({nope: 'nope'});     // false
is.not.domNode({});             // true
is.all.domNode(obj, obj);       // true
is.any.domNode(obj, {nope: 'nope'}); // true

JSON Object Check

Checks if the given value is a pure JSON object.

/**
 * Checks if the given value type is pure json object
 * @param value - Value to check
 * @returns True if value is pure JSON object
 * Interfaces: not, all, any
 */
function json(value: any): boolean;

Usage Example:

is.json({foo: 'bar'});      // true
is.json(toString);          // false (functions are not JSON)
is.not.json([]);            // true
is.all.json({}, 1);         // false
is.any.json({}, 2);         // true

Same Type Check

Checks if the given values are the same type.

/**
 * Checks if the given value types are same type
 * @param value - First value to compare
 * @param other - Second value to compare
 * @returns True if values are same type
 * Interfaces: not
 */
function sameType(value: any, other: any): boolean;

Usage Example:

is.sameType(42, 7);         // true
is.sameType(42, '7');       // false
is.not.sameType(42, 7);     // false

Window Object Check

Checks if the given object is a window object.

/**
 * Checks if the given object is window object
 * @param value - Value to check
 * @returns True if value is window object
 * Interfaces: not, all, any
 */
function windowObject(value: any): boolean;

Usage Example:

is.windowObject(window);           // true
is.windowObject({nope: 'nope'});   // false
is.not.windowObject({});           // true
is.all.windowObject(window, {nope: 'nope'}); // false
is.any.windowObject(window, {nope: 'nope'}); // true

docs

collection-validation.md

configuration.md

date-time.md

environment-detection.md

index.md

numeric-operations.md

pattern-matching.md

presence-checking.md

string-checking.md

type-checking.md

tile.json