phane-js-utils
v1.0.21
Published
Pure JavaScript utility functions
Maintainers
Readme
Kotipalli Phaneendra - Data Type Checking
A lightweight, dependency-free JavaScript utility library for data type checking and input validation.
It provides simple helper functions to reliably determine JavaScript data types and safely work with objects and arrays.
Designed to be minimal, predictable, and well-tested, phane-js-utils works seamlessly in both Node.js and browser environments.
✨ Highlights
- 🔍 Simple and reliable type-checking helpers
- 📦 Object & array utility functions
- 🧪 Fully unit-tested with edge cases
- ⚡ Zero dependencies
- 🌐 Works in Node.js and modern browsers
📦 Installation
npm install phane-js-utils🚀 Quick Example
import {
isNumber,
isString,
isBoolean,
isAnArray
} from "phane-js-utils";
isNumber(42); // true
isString("hello"); // true
isBoolean(false); // true
isAnArray([1, 2, 3]); // true📚 API Reference
All functions are pure, dependency-free, and follow native JavaScript behavior.
isNumber(value)
Checks whether the given value is a JavaScript number.
isNumber(42); // true
isNumber(NaN); // true
isNumber(Infinity); // true
isNumber("42"); // falseisString(value)
Checks whether the given value is a string.
isString("hello"); // true
isString(""); // true
isString(42); // falseisBoolean(value)
Checks whether the given value is a boolean.
isBoolean(true); // true
isBoolean(false); // true
isBoolean(1); // falseisBigint(value)
Checks whether the given value is a bigint.
isBigint(123n); // true
isBigint(123); // falseisFunction(value)
Checks whether the given value is a function.
isFunction(() => {}); // true
isFunction(function () {}); // true
isFunction(class Test {}); // true
isFunction(42); // falseisObject(value)
Checks whether the given value is a plain object (not an array, function, or null).
isObject({}); // true
isObject({ a: 1 }); // true
isObject([]); // false
isObject(null); // falseisAnArray(value)
Checks whether the given value is an array.
isAnArray([]); // true
isAnArray([1, 2, 3]); // true
isAnArray({}); // false🧪 Testing
All utilities are covered with unit tests, including edge cases such as:
NaNandInfinity- Sparse arrays
nullandundefined- Functions, classes, and arrow functions
🎯 Use Cases
- Input validation
- Form data checks
- Frontend and backend utility helpers
- Safer JavaScript type handling
📄 License
MIT
🔗 Links
- GitHub Repository: https://github.com/phane-tech/js-data-type-check
- Demo / Documentation: https://phane-tech.github.io/js-data-type-check/module-DataTypeCheck.html
- Unit Test Cases Reports: https://phane-tech.github.io/js-data-type-check/unit-test-report.html
FOR RUNKIT
const { isString, isAnArray } = require("phane-js-utils");
console.log(isString("Hi")); // true
console.log(isAnArray([1,2,3])); // true