Pure JavaScript utility functions
npm install phane-js-utilsA 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.
---
- ๐ 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
---
``bash`
npm install phane-js-utils
---
`js
import {
isNumber,
isString,
isBoolean,
isAnArray
} from "phane-js-utils";
isNumber(42); // true
isString("hello"); // true
isBoolean(false); // true
isAnArray([1, 2, 3]); // true
`
---
All functions are pure, dependency-free, and follow native JavaScript behavior.
---
Checks whether the given value is a JavaScript number.
`js`
isNumber(42); // true
isNumber(NaN); // true
isNumber(Infinity); // true
isNumber("42"); // false
---
Checks whether the given value is a string.
`js`
isString("hello"); // true
isString(""); // true
isString(42); // false
---
Checks whether the given value is a boolean.
`js`
isBoolean(true); // true
isBoolean(false); // true
isBoolean(1); // false
---
Checks whether the given value is a bigint.
`js`
isBigint(123n); // true
isBigint(123); // false
---
Checks whether the given value is a function.
`js`
isFunction(() => {}); // true
isFunction(function () {}); // true
isFunction(class Test {}); // true
isFunction(42); // false
---
Checks whether the given value is a plain object (not an array, function, or null).
`js`
isObject({}); // true
isObject({ a: 1 }); // true
isObject([]); // false
isObject(null); // false
---
Checks whether the given value is an array.
`js`
isAnArray([]); // true
isAnArray([1, 2, 3]); // true
isAnArray({}); // false
---
All utilities are covered with unit tests, including edge cases such as:
- NaN and Infinitynull
- Sparse arrays
- and undefined
- Functions, classes, and arrow functions
---
- Input validation
- Form data checks
- Frontend and backend utility helpers
- Safer JavaScript type handling
---
MIT
---
- 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
``js
const { isString, isAnArray } = require("phane-js-utils");
console.log(isString("Hi")); // true
console.log(isAnArray([1,2,3])); // true