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

typedcontract

v2.0.0

Published

A wonderfully simple, yet powerful TypeScript and JavaScript code contract library

Downloads

757

Readme

typed-contract

typed-contract is a library to help guard against invalid function inputs and outputs. Using a fluent syntax, it allows a short and descriptive way to protect the system and return useful error messages.

Our goals are:

As the size and complexity of your JavaScript and TypeScript projects continues to grow, edge cases and regressions will occur. Help find them quickly before your users do!

The simple definition of what TypeScript is, is this.... "TypeScript is a superset of JavaScript which primarily provides optional static typing, classes and interfaces. This allows much more insightful and transparent JavaScript and TypeScript application development. Allowing Integrated Development Environments to provide a richer environment for spotting common errors as you type and build your application." - Andre Fischbacher

Code contracts allow you to ensure that your intentions for any property or method are ensured using a code contract. When you are developing an application you can list and specify as many preconditions and postconditions in your code as needed. In typed-contract preconditions are strict requirements that must be met when entering executing an application at runtime. Postconditions describe expectations at the time the method or property code exits at runtime.

Typed-contract allows you to set pre and postconditions in your code to check for certain invariants that you set while writing out a typed-contract. Once you execute a project, a set of classes or functions, the typed-contract can then check that every condition successfully passes, which allows your intentions when building your app to run as smooth as butter.

Typed-contract will allow you and your projects to have more descriptive syntax for your variables, functions, interfaces and classes

typed-contract can be used in either JavaScript or TypeScript environments so the freedom of choice is always yours. See https://github.com/randarp/typed-contract/wiki/Setup-typed-contract.

Here is an example of what a typed-contract looks like... myVar: number = 3.14159265359; Contract.In(myVar, "PI"). isNotNull(). isDefined(). isGreaterThan(3.13). isNotLessThan(3);

and the same goes for postconditions as well

myVar: number = 3.14159265359;

Contract.Out(myVar, "PI").
	isNotNull().
	isDefined().
	isGreaterThan(3.13).
	isNotLessThan(3);

As you can see we can use something known as Function/Method chaining to allow any typed-contract to check for many conditions in one instance of a contract. Each contract that is created will have specific functions based on the data type passed in as a pre or post condition in, making good use of TypeScripts static typing. Here is an example.

varArray: any[] = [1, 2, 3];
varNumber: number = 100;
varString: string = "Hello World";
varBoolean: boolean = true;<br/>

Contract.In(varNumber).
	isLessThan(101).
	isNotNull().
	isGreaterThan(99);<br/>

Contract.In(varArray).
	isDefined().
	isEqualTo([1, 2, 3], 1);<br/>

Contract.In(varString).
	contains("Hello").
	notContains("Goodbye");

If you would like to see all of the documentation click here https://github.com/randarp/typed-contract/wiki

Of course you would like to know what is included in this wonderful code contract library so you can utilize it to the best of it's ability.

Here are the list of the classes that are included in this npm module, and were always thinking of adding more to make the experience even better!