Socket
Book a DemoInstallSign in
Socket

is-check-js

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-check-js

A comprehensive utility library for type checking and validation

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

is-check-js

A comprehensive utility library for type checking and validation in Node.js and JavaScript applications.

Features

  • Comprehensive Type Checking: Over 30 utility functions for type validation
  • TypeScript Support: Full TypeScript definitions included
  • Zero Dependencies: Lightweight with no external dependencies
  • Well Tested: 100% test coverage with Jest
  • Modern JavaScript: Supports all modern JavaScript types including BigInt and Symbol
  • Advanced Validations: Email, URL, IP address, credit card, and more

Installation

yarn add is-check-js

Quick Start

import { isString, isEmail, isEmpty, isPositive } from 'is-check-js';

// Basic type checking
console.log(isString('hello')); // true
console.log(isString(123)); // false

// Advanced validation
console.log(isEmail('user@example.com')); // true
console.log(isEmpty('')); // true
console.log(isPositive(5)); // true

API Reference

Basic Type Checking

isString(value)

Check if value is a string.

isString('hello'); // true
isString(123); // false

isNumber(value)

Check if value is a number (excluding NaN).

isNumber(123); // true
isNumber('123'); // false
isNumber(NaN); // false

isBoolean(value)

Check if value is a boolean.

isBoolean(true); // true
isBoolean('true'); // false

isFunction(value)

Check if value is a function.

isFunction(() => {}); // true
isFunction(Math.max); // true

isArray(value)

Check if value is an array.

isArray([]); // true
isArray([1, 2, 3]); // true
isArray({}); // false

isObject(value)

Check if value is a plain object (not array, null, or other objects).

isObject({}); // true
isObject({ a: 1 }); // true
isObject([]); // false
isObject(null); // false

isObjectLike(value)

Check if value is any type of object (including arrays, dates, etc.).

isObjectLike({}); // true
isObjectLike([]); // true
isObjectLike(new Date()); // true
isObjectLike(null); // false

isDate(value)

Check if value is a valid Date object.

isDate(new Date()); // true
isDate(new Date('invalid')); // false

isRegExp(value)

Check if value is a RegExp object.

isRegExp(/test/); // true
isRegExp(new RegExp('test')); // true

isNull(value), isUndefined(value), isNil(value)

Check for null, undefined, or both.

isNull(null); // true
isUndefined(undefined); // true
isNil(null); // true
isNil(undefined); // true

isSymbol(value), isBigInt(value)

Check for modern JavaScript types.

isSymbol(Symbol('test')); // true
isBigInt(123n); // true

Advanced Validation

isEmpty(value)

Check if value is empty (works with strings, arrays, objects, Maps, Sets).

isEmpty(''); // true
isEmpty([]); // true
isEmpty({}); // true
isEmpty(null); // true
isEmpty('hello'); // false

isEmail(value)

Validate email addresses.

isEmail('user@example.com'); // true
isEmail('invalid-email'); // false

isURL(value)

Validate URLs.

isURL('https://example.com'); // true
isURL('http://localhost:3000'); // true
isURL('not-a-url'); // false

isPhoneNumber(value)

Basic phone number validation.

isPhoneNumber('1234567890'); // true
isPhoneNumber('+1 (555) 123-4567'); // true

isJSON(value)

Check if string is valid JSON.

isJSON('{"name": "John"}'); // true
isJSON('{invalid}'); // false

Number Validation

isPositive(value), isNegative(value), isZero(value)

Number sign validation.

isPositive(5); // true
isNegative(-3); // true
isZero(0); // true

isInteger(value), isFloat(value)

Number type validation.

isInteger(42); // true
isFloat(3.14); // true

isEven(value), isOdd(value)

Even/odd number validation.

isEven(4); // true
isOdd(3); // true

isInRange(value, min, max)

Check if number is within a range.

isInRange(5, 0, 10); // true
isInRange(15, 0, 10); // false

Advanced Format Validation

isCreditCard(value)

Validate credit card numbers using Luhn algorithm.

isCreditCard('4111111111111111'); // true (Visa test number)

isIPv4(value), isIPv6(value)

IP address validation.

isIPv4('192.168.1.1'); // true
isIPv6('2001:0db8:85a3:0000:0000:8a2e:0370:7334'); // true

isHexColor(value)

Hexadecimal color validation.

isHexColor('#ff5733'); // true
isHexColor('#fff'); // true

isUUID(value)

UUID validation.

isUUID('123e4567-e89b-12d3-a456-426614174000'); // true

Utility Functions

isAny(value, ...predicates)

Check if value matches any of the provided predicates.

isAny('hello', isString, isNumber); // true
isAny(123, isString, isNumber); // true

isAll(value, ...predicates)

Check if value matches all of the provided predicates.

isAll('hello', isString, v => v.length > 0); // true

isType(value, type)

Check if value is of a specific type using string comparison.

isType('hello', 'string'); // true
isType([], 'array'); // true
isType(null, 'null'); // true

isTruthy(value), isFalsy(value)

Check truthiness and falsiness.

isTruthy(1); // true
isFalsy(0); // true

getType(value)

Get the type of a value as a string.

getType('hello'); // 'string'
getType([]); // 'array'
getType(null); // 'null'
getType(new Date()); // 'date'

TypeScript Support

The library includes comprehensive TypeScript definitions:

import { isString, isEmail, isEmpty } from 'is-check-js';

const userInput: unknown = getUserInput();

if (isString(userInput)) {
  // TypeScript knows userInput is a string here
  console.log(userInput.toUpperCase());
}

if (isEmail(userInput)) {
  // TypeScript knows userInput is a string (email)
  sendEmail(userInput);
}

Testing

Run the test suite:

yarn test

# Run with coverage
yarn test:coverage

# Run in watch mode
yarn test:watch

Contributing

  • Fork the repository
  • Create your feature branch (git checkout -b feature/amazing-feature)
  • Add tests for your changes
  • Ensure all tests pass (yarn test)
  • Commit your changes (git commit -m 'Add some amazing feature')
  • Push to the branch (git push origin feature/amazing-feature)
  • Open a Pull Request

License

MIT License - see the LICENSE file for details.

Changelog

1.0.0

  • Initial release with comprehensive type checking and validation utilities
  • TypeScript support
  • Full test coverage
  • Zero dependencies

Keywords

type-check

FAQs

Package last updated on 07 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts