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

@bemoje/is

v3.0.0

Published

Type checking and validation utilities with composable validators and detailed error reporting.

Downloads

188

Readme

@bemoje/is

Type checking and validation utilities with composable validators and detailed error reporting.

TypeScript Module

Exports

  • IsArrayWhereEach: Creates a validator function that checks whether the input is an array where all elements are valid according to every validator provided.
  • IsFileExt.
  • IsLength: Creates a function that validates if the length of the input is equal to the specified length. The returned function accepts any value with a 'length' property and is named 'isLen' concatenated with the specified length.
  • ValidatorError: Custom error class for validation failures, providing detailed information about the input, expected outcome, and cause of failure.
  • createGtValidator: Creates a validator function that checks if a value is a number greater than the specified limit.
  • createGteValidator: Creates a validator function that checks if a value is a number greater than or equal to the specified limit.
  • createLtValidator: Creates a validator function that checks if a value is a number less than the specified limit.
  • createLteValidator: Creates a validator function that checks if a value is a number less than or equal to the specified limit.
  • ensureThat. If validation fails, an error is thrown with details about the failure. Validators can return strings indicating the reason for failure, which will be included in the error message.
  • isArray: Checks if the provided value is an array.
  • isChar: Determines whether a string is a single character.
  • isClass: Checks if the given value is a constructor function using 'class' syntax. WARNING: If the running code is minified or mangled, this function may not work as expected. However, it should be resistant to minification/mangling if the 'class' keyword is present in the first line of the function.
  • isConstructor: Checks if the given value is a valid constructor function.
  • isDefined: This function checks if a value is defined or not. It performs a strict comparison against undefined.
  • isDigit: Returns true if the given character is a digit between 0 and 9.
  • isDigits: Returns true if the given string is a string of digits between 0 and 9.
  • isEven: Checks if a number is even.
  • isHex: Checks if a string is a hexadecimal number. Understands prefixes for hex colors, hex decimal and regexp unicode hex.
  • isHexOrUnicode: Checks if a given string is a hexadecimal or unicode.
  • isIntRange: Determine whether the input is an array of two integers in ascending order.
  • isInteger: Checks if the provided number is an integer.
  • isLen2: Determine whether the input has length of 2.
  • isNamedFunction: Checks if the provided value is a named function.
  • isNamedFunctionArray: Checks if the provided value is an array containing only named functions.
  • isNegativeInteger: Checks if a given number is a negative integer.
  • isNegativeNumber: Checks if a given number is negative or zero.
  • isNonZeroNegativeInteger: Checks if a given number is a negative non-zero integer.
  • isNonZeroNegativeNumber: Checks if a given value is a negative number less than zero.
  • isNonZeroPositiveInteger: Checks if a given number is a positive non-zero integer.
  • isNonZeroPositiveNumber: Checks if a given value is a positive number greater than zero.
  • isNumArrayAscending: Determine whether the input is an array of numbers in ascending order. Duplicate values are allowed.
  • isNumericString: Checks if a given string is numeric.
  • isObject.
  • isObjectType.
  • isOdd: Checks if a number is odd.
  • isPosIntArray integer array.
  • isPosIntRange: Checks if the input is an array of exactly two positive integers in ascending order, representing a valid range.
  • isPositiveInteger: Checks if a given number is a positive integer.
  • isPositiveNumber.
  • isPrototype: Checks if the given value is a prototype object
  • isStringArray: Determine whether the input is a string array.
  • isStringWithNoSpacesOrDashes: Checks if the provided value is a string that contains no spaces or dashes.
  • isUniqueNumArrayAscending: Determine whether the input is an array of numbers in ascending order. Duplicate values are not allowed.
  • isValidNumber.

Installation

npm install @bemoje/is

Usage

Basic Type Guards

import { isArray, isInteger, isObject, isPositiveNumber, isEven } from '@bemoje/is'

isArray([1, 2, 3]) // true
isInteger(42) // true
isObject({ a: 1 }) // true
isPositiveNumber(-5) // false
isEven(4) // true

Validate with ensureThat

Assert that values pass validation, throwing detailed errors on failure:

import { ensureThat, isInteger, isPositiveNumber } from '@bemoje/is'

ensureThat(42, isInteger)
// 42

ensureThat(-3, [isInteger, isPositiveNumber])
// throws ValidatorError with cause: { isPositiveNumber: false }

Create Composite Validators

import { IsArrayWhereEach, isInteger, isPositiveNumber } from '@bemoje/is'

const isPosIntArray = IsArrayWhereEach([isInteger, isPositiveNumber])

isPosIntArray([1, 2, 3]) // true
isPosIntArray([1, -2, 3]) // false
isPosIntArray('hello') // false

Length Validation

import { IsLength } from '@bemoje/is'

const isLen3 = IsLength(3)
isLen3([1, 2, 3]) // true
isLen3('abc') // true
isLen3([1, 2]) // false

File Extension Validation

import { IsFileExt } from '@bemoje/is'

const isTs = IsFileExt('ts')
isTs('index.ts') // true
isTs('index.js') // false

Comparison Validators

import { createGtValidator, createLteValidator } from '@bemoje/is'

const isGt10 = createGtValidator(10)
isGt10(15) // true
isGt10(5) // false

const isLte100 = createLteValidator(100)
isLte100(100) // true
isLte100(101) // false

Validation Error Details

import { ValidatorError } from '@bemoje/is'

try {
  ensureThat(-3, [isInteger, isPositiveNumber])
} catch (e) {
  if (e instanceof ValidatorError) {
    console.log(e.input) // -3
    console.log(e.expected) // true
    console.log(e.cause) // { isPositiveNumber: false }
  }
}