npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

barbero

v1.3.0

Published

A lightweight utility library for Boolean evaluations, semantic string parsing, comparisons, and predicate utilities.

Readme

Barbero

Barbero is a lightweight JavaScript utility library providing tools for Boolean evaluations, semantic string parsing, comparisons, logical operations, and predicate utilities. Simplify your true/false logic with this modern, easy-to-use toolkit.


Features

  • Lightweight: Small and efficient, designed to integrate seamlessly with your projects.
  • Boolean Utilities: Perform truthy/falsey checks, comparisons, validations, and predicate compositions.
  • Semantic Parsing: Recognise boolean meaning in strings and numbers — 'yes', 'enabled', 'on', 1, and many more.
  • TypeScript-ready: Ships a full declaration file for first-class TypeScript support, generated from JSDoc annotations.
  • Easy to Use: Clear and intuitive functions for common tasks.
  • Tree-shakable: Import only what you need to minimize bundle size.

Installation

Install Barbero via NPM:

npm install barbero

Or using Yarn:

yarn add barbero

Migrating from boolean?

If you're migrating from the deprecated boolean package, Barbero is a drop-in successor — same behaviour, same zero-dependency philosophy, plus ESM support and stricter TypeScript declarations. See the migration guide for the full import change, function mapping, and behavioural comparison.


Getting Started

Barbero ships three formats to suit any environment.

ES Modules (recommended)

import { isTruthy, parseBoolean } from 'barbero';

Tree-shakable — only the functions you import are included in your bundle.

CommonJS (Node.js)

const { isTruthy, parseBoolean } = require('barbero');

Default import

import Barbero from 'barbero';

Barbero.isTruthy(1);       // true
Barbero.parseBoolean('yes'); // true

Browser (UMD via script tag)

<script src="node_modules/barbero/dist/index.umd.js"></script>
<script>
  Barbero.isTruthy(1);        // true
  Barbero.parseBoolean('yes'); // true
</script>

Usage

Import and use individual functions or the entire library:

Example 1: Truthy/Falsey Checks

import { isTruthy, isFalsey } from 'barbero';

console.log(isTruthy(1)); // true
console.log(isFalsey(0)); // true

Example 2: Null/Undefined/Empty Checks

import { isNullOrUndefined, isEmptyArray } from 'barbero';

console.log(isNullOrUndefined(null)); // true
console.log(isEmptyArray([])); // true
console.log(isEmptyArray([1, 2])); // false

Example 3: Comparisons

import { isEqual, isStrictEqual } from 'barbero';

console.log(isEqual({ a: 1 }, { a: 1 })); // true
console.log(isStrictEqual(1, '1')); // false

Example 4: Logical Operations

import { xor, nand } from 'barbero';

console.log(xor(true, false)); // true
console.log(nand(true, true)); // false

Example 5: Predicate Utilities

import { allPass, anyPass, nonePass, composePredicates } from 'barbero';

const isPositive = (x) => x > 0;
const isEven = (x) => x % 2 === 0;

const isPositiveAndEven = allPass(isPositive, isEven);
console.log(isPositiveAndEven(4)); // true
console.log(isPositiveAndEven(-2)); // false

const isPositiveOrEven = anyPass(isPositive, isEven);
console.log(isPositiveOrEven(-2)); // true

const isNeitherPositiveNorEven = nonePass(isPositive, isEven);
console.log(isNeitherPositiveNorEven(-3)); // true

const customCheck = composePredicates(isPositive, isEven);
console.log(customCheck(4)); // true
console.log(customCheck(3)); // false

API

Core Functions

Full reference

isTruthy(value)

Returns true if the value is truthy.

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

isFalsey(value)

Returns true if the value is falsey.

isFalsey(0); // true
isFalsey('hello'); // false

Validation Functions

Full reference

isNullOrUndefined(value)

Returns true if the value is null or undefined.

isNullOrUndefined(null); // true
isNullOrUndefined(undefined); // true
isNullOrUndefined(''); // false

isUndefinedNullOrEmpty(value)

Returns true if the value is undefined, null, NaN, an empty string (including whitespace-only), an empty array, or an empty plain object.

isUndefinedNullOrEmpty(null);    // true
isUndefinedNullOrEmpty('');      // true
isUndefinedNullOrEmpty([]);      // true
isUndefinedNullOrEmpty({});      // true
isUndefinedNullOrEmpty(0);       // false
isUndefinedNullOrEmpty(false);   // false

isEmptyArray(array)

Returns true if the array is empty.

isEmptyArray([]); // true
isEmptyArray([1]); // false

isEmptyObject(object)

Returns true if the object has no keys.

isEmptyObject({}); // true
isEmptyObject({ a: 1 }); // false

isArray(value)

Returns true if the value is an array.

isArray([1, 2, 3]); // true
isArray('hello');   // false

isObject(value)

Returns true if the value is a non-null, non-array object.

isObject({ key: 'value' }); // true
isObject([1, 2, 3]);        // false
isObject(null);             // false

isFunction(value)

Returns true if the value is a function.

isFunction(() => {});  // true
isFunction(123);       // false

isDate(value)

Returns true if the value is a Date instance.

isDate(new Date());    // true
isDate('2026-01-01'); // false

isRegExp(value)

Returns true if the value is a regular expression.

isRegExp(/abc/);  // true
isRegExp('abc');  // false

Type System Functions

Full reference

isNumber(value)

Returns true if the value has type 'number' (including NaN).

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

isString(value)

Returns true for primitive strings. Returns false for boxed String objects.

isString('hello');          // true
isString(new String('hi')); // false

isBoolean(value)

Returns true for primitive booleans. Returns false for boxed Boolean objects.

isBoolean(true);               // true
isBoolean(new Boolean(false)); // false

isSymbol(value)

Returns true for Symbol values.

isSymbol(Symbol());       // true
isSymbol('symbol');       // false

isBigInt(value)

Returns true for BigInt values.

isBigInt(9n);        // true
isBigInt(BigInt(9)); // true
isBigInt(9);         // false

isPrimitive(value)

Returns true for all primitive types including null and undefined.

isPrimitive(1);         // true
isPrimitive(null);      // true
isPrimitive(undefined); // true
isPrimitive({});        // false

isClassInstance(value)

Returns true for instances of non-Object constructors (e.g. Date, Map, custom classes).

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

Number / Math Functions

Full reference

isInteger(value)

Returns true if the value is an integer. Does not coerce — strings and floats return false.

isInteger(4);        // true
isInteger(4.5);      // false
isInteger(NaN);      // false

isFloat(value)

Returns true if the value is a finite number that is not an integer.

isFloat(4.5);      // true
isFloat(4);        // false
isFloat(Infinity); // false

isPositive(value)

Returns true if the value is strictly greater than zero. 0, -0, and NaN return false.

isPositive(1);    // true
isPositive(0);    // false
isPositive(NaN);  // false

isNegative(value)

Returns true if the value is strictly less than zero. -0 returns false.

isNegative(-1);  // true
isNegative(0);   // false
isNegative(-0);  // false — -0 < 0 is false in JavaScript

isZero(value)

Returns true if the value is 0 or -0.

isZero(0);   // true
isZero(-0);  // true
isZero(1);   // false

isEven(value)

Returns true if the value is an even integer. Non-integers return false.

isEven(4);    // true
isEven(3);    // false
isEven(2.5);  // false

isOdd(value)

Returns true if the value is an odd integer. Non-integers return false.

isOdd(3);    // true
isOdd(4);    // false
isOdd(3.1);  // false

isInRange(value, min, max)

Returns true if the value is within [min, max], inclusive on both bounds.

isInRange(5, 1, 10);  // true
isInRange(1, 1, 10);  // true  — inclusive
isInRange(11, 1, 10); // false

isDivisibleBy(value, divisor)

Returns true if value is an integer evenly divisible by divisor. Guards against division by zero and non-integer inputs.

isDivisibleBy(9, 3);   // true
isDivisibleBy(9, 0);   // false — division by zero guard
isDivisibleBy(9.5, 3); // false — non-integer value

isFiniteNumber(value)

Returns true if the value is a finite number. Returns false for NaN, Infinity, -Infinity, and non-numbers.

isFiniteNumber(42);       // true
isFiniteNumber(Infinity); // false
isFiniteNumber(NaN);      // false

isNaNValue(value)

Returns true if the value is exactly NaN. Uses Number.isNaN — does not coerce, so isNaNValue(undefined) returns false.

isNaNValue(NaN);        // true
isNaNValue(undefined);  // false — unlike global isNaN, no coercion
isNaNValue(42);         // false

Boolean Parsing

Full reference

| Function | Description | |----------|-------------| | parseBoolean(value) | Returns true if the value is a recognised truthy representation ('yes', 'true', 'on', '1', 1, etc.); false for everything else | | isBooleanable(value) | Returns true if the value is any recognised boolean representation — either truthy or falsy | | isTruthyString(value) | Returns true if the value is one of the recognised truthy semantic representations | | isFalseyString(value) | Returns true if the value is one of the recognised falsy semantic representations |

parseBoolean(value)

Returns true if the value is a recognised truthy semantic representation. Direct replacement for the deprecated boolean() function.

parseBoolean('yes');      // true
parseBoolean('enabled');  // true
parseBoolean(1);          // true
parseBoolean('no');       // false
parseBoolean('maybe');    // false

isBooleanable(value)

Returns true if the value is any recognised boolean representation — either truthy or falsy. Note that 'no', 'false', '0', etc. are booleanable even though they represent false.

isBooleanable('yes');    // true
isBooleanable('no');     // true  — 'no' is booleanable even though it's falsy
isBooleanable('maybe');  // false
isBooleanable(null);     // false

isTruthyString(value)

Returns true if the value is one of the recognised truthy semantic representations. Complements isTruthy for string/number input forms.

isTruthyString('yes');      // true
isTruthyString('enabled');  // true
isTruthyString('no');       // false
isTruthyString(1);          // true

isFalseyString(value)

Returns true if the value is one of the recognised falsy semantic representations. Complements isFalsey for string/number input forms.

isFalseyString('no');        // true
isFalseyString('disabled');  // true
isFalseyString('yes');       // false
isFalseyString(0);           // true

String Content Functions

Full reference

| Function | Description | |----------|-------------| | isNumericString(value) | Returns true if the value is a non-empty string that converts to a valid number | | isAlpha(value) | Returns true if the string contains only ASCII letters | | isAlphanumeric(value) | Returns true if the string contains only ASCII letters and digits | | isUpperCase(value) | Returns true if the string is non-empty and all characters are upper case | | isLowerCase(value) | Returns true if the string is non-empty and all characters are lower case | | isPalindrome(value) | Returns true if the string reads the same forwards and backwards (case-sensitive) | | isBlankString(value) | Returns true if the string is empty or whitespace-only | | stringStartsWith(value, prefix) | Returns true if the string begins with the given prefix | | stringEndsWith(value, suffix) | Returns true if the string ends with the given suffix | | stringIncludes(value, substring) | Returns true if the string contains the given substring |

isNumericString(value)

Returns true if the value is a non-empty string that converts to a valid number.

isNumericString('42');    // true
isNumericString('3.14');  // true
isNumericString('abc');   // false
isNumericString('');      // false

isAlpha(value)

Returns true if the string contains only ASCII letters (a-z, A-Z). Empty string returns false.

isAlpha('hello');   // true
isAlpha('hello1');  // false
isAlpha('');        // false

isAlphanumeric(value)

Returns true if the string contains only ASCII letters and digits. Empty string returns false.

isAlphanumeric('hello1');  // true
isAlphanumeric('hello!');  // false
isAlphanumeric('');        // false

isUpperCase(value)

Returns true if the string is non-empty and all characters are upper case. Strings with no alphabetical characters (e.g. '123') return true.

isUpperCase('HELLO');  // true
isUpperCase('123');    // true  — no lower-case characters present
isUpperCase('Hello');  // false
isUpperCase('');       // false

isLowerCase(value)

Returns true if the string is non-empty and all characters are lower case. Strings with no alphabetical characters (e.g. '123') return true.

isLowerCase('hello');  // true
isLowerCase('123');    // true  — no upper-case characters present
isLowerCase('Hello');  // false
isLowerCase('');       // false

isPalindrome(value)

Returns true if the string reads the same forwards and backwards. Comparison is case-sensitive. Empty string returns true.

isPalindrome('racecar');  // true
isPalindrome('');         // true  — empty string is vacuously a palindrome
isPalindrome('Racecar');  // false — case-sensitive
isPalindrome('hello');    // false

isBlankString(value)

Returns true if the string is empty or contains only whitespace.

isBlankString('');     // true
isBlankString('   ');  // true
isBlankString('hello'); // false

stringStartsWith(value, prefix)

Returns true if the string begins with the given prefix. Both arguments must be strings.

stringStartsWith('hello', 'hel');    // true
stringStartsWith('hello', '');      // true  — empty prefix matches everything
stringStartsWith('hello', 'world'); // false

stringEndsWith(value, suffix)

Returns true if the string ends with the given suffix. Both arguments must be strings.

stringEndsWith('hello', 'llo');    // true
stringEndsWith('hello', '');      // true  — empty suffix matches everything
stringEndsWith('hello', 'world'); // false

stringIncludes(value, substring)

Returns true if the string contains the given substring. Both arguments must be strings.

stringIncludes('hello', 'ell');  // true
stringIncludes('hello', '');    // true  — empty substring matches everything
stringIncludes('hello', 'xyz'); // false

Comparison Functions

Full reference

isEqual(a, b)

Performs deep equality comparison between two values.

isEqual({ a: 1 }, { a: 1 }); // true
isEqual([1, 2], [1, 2]); // true
isEqual(1, '1'); // false

isStrictEqual(a, b)

Performs strict equality comparison (no type coercion).

isStrictEqual(1, 1); // true
isStrictEqual(1, '1'); // false

Logical Functions

Full reference

xor(a, b)

Returns true if only one of the arguments is true.

xor(true, false); // true
xor(true, true); // false

nand(a, b)

Returns true if not both arguments are true.

nand(true, true); // false
nand(true, false); // true

Predicate Utilities

Full reference

allPass(...predicates)

Returns a function that checks if all predicates pass for the given input.

const isPositive = (x) => x > 0;
const isEven = (x) => x % 2 === 0;
const isPositiveAndEven = allPass(isPositive, isEven);
console.log(isPositiveAndEven(4)); // true
console.log(isPositiveAndEven(-2)); // false

anyPass(...predicates)

Returns a function that checks if any predicate passes for the given input.

const isPositiveOrEven = anyPass(isPositive, isEven);
console.log(isPositiveOrEven(-2)); // true
console.log(isPositiveOrEven(-3)); // false

nonePass(...predicates)

Returns a function that checks if no predicates pass for the given input.

const isNeitherPositiveNorEven = nonePass(isPositive, isEven);
console.log(isNeitherPositiveNorEven(-3)); // true
console.log(isNeitherPositiveNorEven(4)); // false

composePredicates(...predicates)

Composes multiple predicates into a single predicate function that tests them sequentially.

const customCheck = composePredicates(isPositive, isEven);
console.log(customCheck(4)); // true
console.log(customCheck(3)); // false

Documentation

Contributions are welcome — please open an issue or submit a pull request on GitHub.


License

Barbero is licensed under the MIT License.


Acknowledgements

Inspired by the need for clear and simple Boolean utilities in JavaScript.