Comprehensive JavaScript utility library with 150+ functions for objects, arrays, dates, strings, numbers, and more
Comprehensive type checking utilities for runtime validation and type guards. Includes checks for all JavaScript primitive types, built-in objects, DOM elements, and web API types. Essential for robust error handling and input validation.
Type checking functions for JavaScript primitive types with TypeScript type guards.
/**
* Check if value is an array
* @param val - Value to check
* @returns True if value is array
*/
function isArray(val: any): val is any[];
/**
* Check if value is a string
* @param val - Value to check
* @returns True if value is string
*/
function isString(val: any): val is string;
/**
* Check if value is a number (excluding NaN)
* @param val - Value to check
* @returns True if value is number
*/
function isNumber(val: any): val is number;
/**
* Check if value is a boolean
* @param val - Value to check
* @returns True if value is boolean
*/
function isBoolean(val: any): val is boolean;
/**
* Check if value is a function
* @param val - Value to check
* @returns True if value is function
*/
function isFunction(val: any): val is Function;
/**
* Check if value is a symbol
* @param val - Value to check
* @returns True if value is symbol
*/
function isSymbol(val: any): val is symbol;Type checking for various object types and complex structures.
/**
* Check if value is an object (excluding null and arrays)
* @param val - Value to check
* @returns True if value is object
*/
function isObject(val: any): val is object;
/**
* Check if value is a plain object (created by {} or new Object())
* @param val - Value to check
* @returns True if value is plain object
*/
function isPlainObject(val: any): val is object;
/**
* Check if value is a Date object
* @param val - Value to check
* @returns True if value is Date
*/
function isDate(val: any): val is Date;
/**
* Check if value is a RegExp object
* @param val - Value to check
* @returns True if value is RegExp
*/
function isRegExp(val: any): val is RegExp;
/**
* Check if value is an Error object
* @param val - Value to check
* @returns True if value is Error
*/
function isError(val: any): val is Error;
/**
* Check if value is a TypeError object
* @param val - Value to check
* @returns True if value is TypeError
*/
function isTypeError(val: any): val is TypeError;Type checking for ES6+ collection types.
/**
* Check if value is a Map object
* @param val - Value to check
* @returns True if value is Map
*/
function isMap(val: any): val is Map<any, any>;
/**
* Check if value is a WeakMap object
* @param val - Value to check
* @returns True if value is WeakMap
*/
function isWeakMap(val: any): val is WeakMap<any, any>;
/**
* Check if value is a Set object
* @param val - Value to check
* @returns True if value is Set
*/
function isSet(val: any): val is Set<any>;
/**
* Check if value is a WeakSet object
* @param val - Value to check
* @returns True if value is WeakSet
*/
function isWeakSet(val: any): val is WeakSet<any>;Specialized checks for null, undefined, and related states.
/**
* Check if value is null
* @param val - Value to check
* @returns True if value is null
*/
function isNull(val: any): val is null;
/**
* Check if value is undefined
* @param val - Value to check
* @returns True if value is undefined
*/
function isUndefined(val: any): val is undefined;
/**
* Check if value is NaN
* @param val - Value to check
* @returns True if value is NaN
*/
function isNaN(val: any): boolean;
/**
* Check if value is null or undefined
* @param val1 - First value
* @param val2 - Second value (optional)
* @returns True if both values are null/undefined or equal
*/
function eqNull(val1: any, val2?: any): boolean;Specialized number type checking including finite, integer, and float checks.
/**
* Check if value is a finite number
* @param val - Value to check
* @returns True if value is finite number
*/
function isFinite(val: any): boolean;
/**
* Check if value is an integer
* @param val - Value to check
* @returns True if value is integer
*/
function isInteger(val: any): boolean;
/**
* Check if value is a float (non-integer number)
* @param val - Value to check
* @returns True if value is float
*/
function isFloat(val: any): boolean;Type checking for browser and DOM-related objects.
/**
* Check if value is a DOM element
* @param val - Value to check
* @returns True if value is DOM element
*/
function isElement(val: any): val is Element;
/**
* Check if value is a Document object
* @param val - Value to check
* @returns True if value is Document
*/
function isDocument(val: any): val is Document;
/**
* Check if value is a Window object
* @param val - Value to check
* @returns True if value is Window
*/
function isWindow(val: any): val is Window;
/**
* Check if value is a FormData object
* @param val - Value to check
* @returns True if value is FormData
*/
function isFormData(val: any): val is FormData;
/**
* Check if value is an Arguments object
* @param val - Value to check
* @returns True if value is Arguments
*/
function isArguments(val: any): val is IArguments;Utilities for checking value states and emptiness.
/**
* Check if value is empty (null, undefined, empty string, empty array, empty object)
* @param val - Value to check
* @returns True if value is considered empty
*/
function isEmpty(val: any): boolean;
/**
* Check if date is a leap year
* @param date - Date to check
* @returns True if year is leap year
*/
function isLeapYear(date: Date | number): boolean;
/**
* Check if date is valid
* @param date - Date to validate
* @returns True if date is valid
*/
function isValidDate(date: any): boolean;Advanced comparison utilities for deep equality checking.
/**
* Deep equality comparison
* @param val1 - First value
* @param val2 - Second value
* @returns True if values are deeply equal
*/
function isEqual(val1: any, val2: any): boolean;
/**
* Deep equality comparison with custom comparator
* @param val1 - First value
* @param val2 - Second value
* @param callback - Custom comparison function
* @returns True if values are equal according to callback
*/
function isEqualWith(
val1: any,
val2: any,
callback: (value1: any, value2: any, key?: string) => boolean | undefined
): boolean;
/**
* Check if object matches source properties
* @param obj - Object to check
* @param source - Source object with properties to match
* @returns True if object contains all source properties with same values
*/
function isMatch(obj: any, source: any): boolean;Utilities for getting detailed type information.
/**
* Get detailed type of value
* @param val - Value to analyze
* @returns Detailed type string
*/
function getType(val: any): string;Usage Examples:
import {
isArray, isString, isNumber, isObject, isEmpty,
isEqual, isValidDate, getType
} from 'xe-utils';
// Basic type checking
const data = ['hello', 42, { name: 'Alice' }, null];
data.forEach(item => {
if (isString(item)) {
console.log(`String: ${item.toUpperCase()}`);
} else if (isNumber(item)) {
console.log(`Number: ${item * 2}`);
} else if (isObject(item)) {
console.log(`Object:`, item);
}
});
// Validation
function validateUser(user) {
if (isEmpty(user)) {
throw new Error('User data is required');
}
if (!isString(user.name) || isEmpty(user.name)) {
throw new Error('Valid name is required');
}
if (!isNumber(user.age) || user.age < 0) {
throw new Error('Valid age is required');
}
return true;
}
// Deep comparison
const obj1 = { user: { name: 'Alice', preferences: { theme: 'dark' } } };
const obj2 = { user: { name: 'Alice', preferences: { theme: 'dark' } } };
console.log(isEqual(obj1, obj2)); // true
// Type information
console.log(getType([])); // 'Array'
console.log(getType(new Date())); // 'Date'
console.log(getType(/regex/)); // 'RegExp'Install with Tessl CLI
npx tessl i tessl/npm-xe-utils