types-checker-js
v1.0.3
Published
A comprehensive utility library for checking and processing various data types in JavaScript. Includes functions for validating arrays, dates, IP addresses, objects, promises, functions, strings, and UUIDs. Suitable for both frontend and backend developer
Downloads
9
Readme
types-checker.js
types-checker.js
is a utility library for checking and processing various data types in JavaScript.
Installation
You can install types-checker.js
using npm:
npm install types-checker.js
const typesChecker = require('types-checker.js');
// Example usage
const isString = typesChecker.isString('Hello, world!');
console.log(isString); // Output: true
const isArray = typesChecker.isArray([1, 2, 3]);
console.log(isArray); // Output: true
const isDate = typesChecker.isDate(new Date());
console.log(isDate); // Output: true
Primitive Types Checking Functions
isNumber(value)
: Checks if the value is a number.isString(value)
: Checks if the value is a string.isBoolean(value)
: Checks if the value is a boolean.isUndefined(value)
: Checks if the value is undefined.isSymbol(value)
: Checks if the value is a symbol.isBigInt(value)
: Checks if the value is a BigInt.
String Checking Functions
isString(value)
: Checks if the value is a string.isNonEmptyString(value)
: Checks if the value is a non-empty string.isAlpha(value)
: Checks if the string consists only of alphabetic characters.isAlphanumeric(value)
: Checks if the string consists of alphanumeric characters.isEmail(value)
: Checks if the string is a valid email address.isUrl(value)
: Checks if the string is a valid URL.
Array Checking Functions
isArray(value)
: Checks if the value is an array.isArrayOfNumbers(value)
: Checks if every element in the array is a number.isArrayOfStrings(value)
: Checks if every element in the array is a string.isArrayOfObjects(value)
: Checks if every element in the array is an object.isArrayOfBooleans(value)
: Checks if every element in the array is a boolean value (true or false).isArrayOf(type, value)
: Checks if every element in the array is of the specified type.
Date Checking Functions
isDate(value)
: Checks if the value is a Date object.isBeforeDate(value, referenceDate)
: Checks if the given date is before the reference date.isAfterDate(value, referenceDate)
: Checks if the given date is after the reference date.isDateInRange(value, startDate, endDate)
: Checks if the given date is within the specified date range.
Function Checking Functions
isFunction(value)
: Checks if the value is a function.hasArity(value, expectedArity)
: Checks if the function has the expected number of parameters (arity).hasMinArity(value, minArity)
: Checks if the function has at least the specified minimum number of parameters.hasMaxArity(value, maxArity)
: Checks if the function has at most the specified maximum number of parameters.isAsyncFunction(value)
: Checks if the value is an asynchronous function (async function).isGeneratorFunction(value)
: Checks if the value is a generator function.isConstructor(value)
: Checks if the value is a constructor function (can be used with the 'new' keyword).
Object Checking Functions
isObject(value)
: Checks if the value is an object.isObjectWithKeys(value, keys)
: Checks if the object has all the specified keys.isObjectOf(value, key, type)
: Checks if the value of the specified key in the object is of the specified type.isObjectWithKeysAndTypes(value, keyTypeMap)
: Checks if the object has keys matching the specified types.isObjectWithNestedObjects(value)
: Checks if the object contains nested objects.
Promise Checking Functions
isPromise(value)
: Checks if the value is a Promise.isFulfilledPromise(value)
: Checks if the value is a fulfilled Promise (resolved).isRejectedPromise(value)
: Checks if the value is a rejected Promise.isPendingPromise(value)
: Checks if the value is a pending Promise
IP Checking Functions
isIPv4(value)
: Checks if the value is a valid IPv4 address.isIPv6(value)
: Checks if the value is a valid IPv6 address.
UUID Checking Functions
isUUID(value)
: Checks if the value is a valid UUID (any version).isUUIDv3(value)
: Checks if the value is a valid UUIDv3.isUUIDv4(value)
: Checks if the value is a valid UUIDv4.isUUIDv5(value)
: Checks if the value is a valid UUIDv5.