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

ts-verify

v1.0.5

Published

A super simple library for validating inputs with decorators

Readme

Verify-TS

NPM Version

This package provides a decorator to help with verifying input to methods.

Install

npm i ts-verify

TypeScript Usage

To use in typescript, import the functions.

import { is, validate } from "ts-verify";

To verify parameters of a method, use like this:

@validate()
public testOneNumber(@is((v) => v > 0) value: number): number {
    return value;
}

In this example, the value parameter will throw an exception if a number is pased that is not greater than 0.

We can use any function that returns a boolean value:

@validate()
public testArraySumGteTen(
    @is((a: number[]) => a.reduce((p, c) => p + c) >= 10) array: number[]
) {
     return array;
}

This will throw if the passed array of numbers does not sum to at least 10.

Type Checking

You can also ensure types are correct:

class PaymentProvider {
    @validate()
    public pay(@is((v) => v > 0, "number") value: number) {
        // Omitted
    }
}

Without the additional "number" parameter, the following would be valid:

pay("4");

However, with this additional checking, the above will throw.

Alternatively, you can just check for a type:

class MyClass {
    @validate()
    public thisIsAString(@is("string") myString: string) {
        // Omitted
    }
}

Contextual Checking

Validation functions can access the object the method is being called on:

class Player {
    private energy: number = 50;
    @validate()
    public doAction(@is((e, context:Player) => energy >= e) energyCost: number): void {
        // Omitted
    }
}

The optional second parameter to an @is call will pass a reference to the object. We can therefore access methods and fields on this object. For typechecking, either the function or parameter must have a type parameter/annotation, i.e.:

@is<Player>((e, context) => ... )

or

@is((e,context:Player) => ... )

Full Method Checking

A validation function can be called inside the @validate() call as well. This function has access to all arguments in the method, for example:

class RandomGenerator {
    @validate({ argFn: (a, b) => a < b })
    public nextInt(@is("number") min: number, @is("number") max: number): number {
        return ~~(Math.random() * (max - min) + min);
    }
}

The order of the arguments in the validation function is the same order as passed in the method. In this example, a would be min, and b would be max.

The validation function inside @validate() can also access the object context. Note the name of the argument inside the object passed to @validate():

class SpaceMission {
    private fuel = 100;

    @validate({ contextFn: (context, a, b) => a + b <= context.fuel })
    public launch(fuelToDestination: number, fuelToReturn: number) {
        // Omitted
    }
}

The first parameter to contextFn is the object. The remaining are the method arguments. This can be contrasted to argFn which just passes the arguments. For a more complete example:

class SpaceMission {
    private fuel = 100;

    @validate({ contextFn: (context, a, b) => a + b <= context.fuel })
    public launch(
        @is((f) => f > 0, "number") fuelToDestination: number,
        @is((f) => f > 0, "number") fuelToReturn: number
    ) {
        // Omitted
    }
}