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';
console.log(isString('hello'));
console.log(isString(123));
console.log(isEmail('user@example.com'));
console.log(isEmpty(''));
console.log(isPositive(5));
API Reference
Basic Type Checking
isString(value)
Check if value is a string.
isString('hello');
isString(123);
isNumber(value)
Check if value is a number (excluding NaN).
isNumber(123);
isNumber('123');
isNumber(NaN);
isBoolean(value)
Check if value is a boolean.
isBoolean(true);
isBoolean('true');
isFunction(value)
Check if value is a function.
isFunction(() => {});
isFunction(Math.max);
isArray(value)
Check if value is an array.
isArray([]);
isArray([1, 2, 3]);
isArray({});
isObject(value)
Check if value is a plain object (not array, null, or other objects).
isObject({});
isObject({ a: 1 });
isObject([]);
isObject(null);
isObjectLike(value)
Check if value is any type of object (including arrays, dates, etc.).
isObjectLike({});
isObjectLike([]);
isObjectLike(new Date());
isObjectLike(null);
isDate(value)
Check if value is a valid Date object.
isDate(new Date());
isDate(new Date('invalid'));
isRegExp(value)
Check if value is a RegExp object.
isRegExp(/test/);
isRegExp(new RegExp('test'));
isNull(value), isUndefined(value), isNil(value)
Check for null, undefined, or both.
isNull(null);
isUndefined(undefined);
isNil(null);
isNil(undefined);
isSymbol(value), isBigInt(value)
Check for modern JavaScript types.
isSymbol(Symbol('test'));
isBigInt(123n);
Advanced Validation
isEmpty(value)
Check if value is empty (works with strings, arrays, objects, Maps, Sets).
isEmpty('');
isEmpty([]);
isEmpty({});
isEmpty(null);
isEmpty('hello');
isEmail(value)
Validate email addresses.
isEmail('user@example.com');
isEmail('invalid-email');
isURL(value)
Validate URLs.
isURL('https://example.com');
isURL('http://localhost:3000');
isURL('not-a-url');
isPhoneNumber(value)
Basic phone number validation.
isPhoneNumber('1234567890');
isPhoneNumber('+1 (555) 123-4567');
isJSON(value)
Check if string is valid JSON.
isJSON('{"name": "John"}');
isJSON('{invalid}');
Number Validation
isPositive(value), isNegative(value), isZero(value)
Number sign validation.
isPositive(5);
isNegative(-3);
isZero(0);
isInteger(value), isFloat(value)
Number type validation.
isInteger(42);
isFloat(3.14);
isEven(value), isOdd(value)
Even/odd number validation.
isEven(4);
isOdd(3);
isInRange(value, min, max)
Check if number is within a range.
isInRange(5, 0, 10);
isInRange(15, 0, 10);
Advanced Format Validation
isCreditCard(value)
Validate credit card numbers using Luhn algorithm.
isCreditCard('4111111111111111');
isIPv4(value), isIPv6(value)
IP address validation.
isIPv4('192.168.1.1');
isIPv6('2001:0db8:85a3:0000:0000:8a2e:0370:7334');
isHexColor(value)
Hexadecimal color validation.
isHexColor('#ff5733');
isHexColor('#fff');
isUUID(value)
UUID validation.
isUUID('123e4567-e89b-12d3-a456-426614174000');
Utility Functions
isAny(value, ...predicates)
Check if value matches any of the provided predicates.
isAny('hello', isString, isNumber);
isAny(123, isString, isNumber);
isAll(value, ...predicates)
Check if value matches all of the provided predicates.
isAll('hello', isString, v => v.length > 0);
isType(value, type)
Check if value is of a specific type using string comparison.
isType('hello', 'string');
isType([], 'array');
isType(null, 'null');
isTruthy(value), isFalsy(value)
Check truthiness and falsiness.
isTruthy(1);
isFalsy(0);
getType(value)
Get the type of a value as a string.
getType('hello');
getType([]);
getType(null);
getType(new Date());
TypeScript Support
The library includes comprehensive TypeScript definitions:
import { isString, isEmail, isEmpty } from 'is-check-js';
const userInput: unknown = getUserInput();
if (isString(userInput)) {
console.log(userInput.toUpperCase());
}
if (isEmail(userInput)) {
sendEmail(userInput);
}
Testing
Run the test suite:
yarn test
yarn test:coverage
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