nhb-toolbox
Version:
A versatile collection of smart, efficient, and reusable utility functions, classes and types for everyday development needs.
60 lines (59 loc) • 1.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.isNumber = isNumber;
exports.isString = isString;
exports.isInteger = isInteger;
exports.isPositiveInteger = isPositiveInteger;
exports.isBoolean = isBoolean;
exports.isNull = isNull;
exports.isUndefined = isUndefined;
exports.isSymbol = isSymbol;
exports.isBigInt = isBigInt;
exports.isPrimitive = isPrimitive;
exports.isNormalPrimitive = isNormalPrimitive;
exports.isNonEmptyString = isNonEmptyString;
exports.isFalsy = isFalsy;
exports.isTruthy = isTruthy;
function isNumber(value) {
return typeof value === 'number' && Number.isFinite(value);
}
function isString(value) {
return typeof value === 'string';
}
function isInteger(value) {
return isNumber(value) && Number.isInteger(value);
}
function isPositiveInteger(value) {
return isInteger(value) && value > 0;
}
function isBoolean(value) {
return typeof value === 'boolean';
}
function isNull(value) {
return value === null;
}
function isUndefined(value) {
return value === undefined;
}
function isSymbol(value) {
return typeof value === 'symbol';
}
function isBigInt(value) {
return typeof value === 'bigint';
}
function isPrimitive(value) {
return (value === null ||
['string', 'number', 'boolean', 'symbol', 'bigint', 'undefined'].includes(typeof value));
}
function isNormalPrimitive(value) {
return value == null || ['string', 'number', 'boolean', 'undefined'].includes(typeof value);
}
function isNonEmptyString(value) {
return isString(value) && value?.length > 0;
}
function isFalsy(value) {
return !value;
}
function isTruthy(value) {
return Boolean(value);
}