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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ents24/be-sure

v2.0.4

Published

NPM module for terse, 'throwy' validation

Readme

Be Sure

NPM module for terse, "throwy" runtime validation. Extremely lightweight, zero dependency, with TypeScript support.

A common problem in web apps is where to validate parameters, and how, and what to do on failure. On one hand, it's best if every function validates its params thoroughly. On the other hand validation-in-place can be verbose and make modules harder to read. beSure attempts to provide the shortest validation syntax possible to keep code DRY and encourage consistent use by:

  1. Being very concise
  2. Always throwing on validation failure
  3. Applying customisation and handler logic elsewhere

It probably belongs at specific level(s) of an app e.g. "all standalone libs" or "all functions in the state-management layer" - thrown errors are therefore anticipated at that level and error handling is applied higher up.

BEFORE - verbose, boilerplate, hard to read

UPDATE_USER_ACTION(userId, userName, dateOfBirth){
  if (typeof userId !== 'number' || userId != == toInteger(value)) {
    throw 'Invalid userId: ' + userId;
  }

  if (typeof userName !== 'string' || userName.length < 5) {
    throw 'Invalid userName: ' + userName;
  }

  if (dateOfBirth instanceof Date !== true || dateOfBirth < new Date()) {
    throw 'Invalid dateOfBirth: ' + dateOfBirth;
  }

  // function body ...
}

AFTER - terse, consistent

UPDATE_USER_ACTION(userId, userName, dateOfBirth){
    beSure(userId, 'id')
    beSure(userName, 'string-not-empty')
    beSure(dateOfBirth, 'date-in-past')

  // function body ...
}

Simple Use

Import and use basic validators

import { beSure } from '@ents24/be-sure'
beSure(myParam, 'slug')

Custom Error Class / Text

Include an error type to instantiate and throw where needed

import { beSure } from '@ents24/be-sure'
class MySpecificError extends Error {}

// Type only
beSure(myParam, 'slug', MySpecificError)

// Or include text, too
beSure(myParam, 'slug', MySpecificError, 'My specific message')

Custom Use

Provide your own key / validator combinations for later use (see custom.js for examples)