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

@lengin/hay

v0.4.3

Published

Run-time checking of javascript types

Readme

What is Hay?

Hay is for execution of run-time type checks. Similar to React Type checks, except that this library was originally written for nondeterministic result object (e.g. input from user).

A use case for writing this library is writting an internal tool for data analytics display to ensure the transformed data matches the input type of different charts (e.g. bar chart, pie chart, etc...).

Installation?

Using npm:

npm install --save-dev @lengin/hay

Sample Code

Importing Hay

import { Hay, HayTypes } from '@lengin/hay';

Check for validity

let obj = ...
Hay.check(obj, HayTypes.object);  //return boolean

Get object with display highlights & error messages

let output = Hay.getMessages();

//output[0]: array of messages (string)
//output[1] = object after JSON.stringify, wrapped with highlight and formatted with spaces.
Hay.check({ a: 1 }, HayTypes.object);

Documentation

HayTypes

Object-based | Type | Description | Positive Examples | Usage | | -----|-------------|-------------------|-------| | number | Return true if target is a number | E.g. 0, 1, 2 | HayTypes.number | | string | Return true if target is a string | "qwerty" | HayTypes.string | | bool | Return true if target is a boolean | true, false | HayTypes.bool | | object | Return true if target is an object | {} | HayTypes.object | | array | Return true if target is a array | [] | HayTypes.array | | func | Return true if target is a function | function() {} | HayTypes.func | | none | Return true if target is null or undefined | null or undefined | HayTypes.none | | generator | Return true if target is a generator function | function*() {} | HayTypes.generator | Add-on | Type | Description | Positive Examples | Usage | | -----|-------------|-------------------|-------| | required | Besides the rule used, the object need to exist. | - | HayTypes.number.required | Function-based | Type | Description | Positive Examples | Usage | | -----|-------------|-------------------|-------| | oneOf | Takes in an array of HayType. Return true if target type is any one of them. | [HayTypes.number, HayTypes.string] | HayTypes.oneOf([HayTypes.number, HayTypes.string]) | | arrayOf | Takes in a HayType. Return true if type of target is an array of them. | HayTypes.number, HayTypes.string | HayTypes.arrayOf(HayTypes.number) | | shapeOf | Takes in an Object. Return true if shape of target is the same. | { 'val': HayTypes.number } | HayTypes.shapeOf({ 'val': HayTypes.number }) | HayTypes.number | Type | Description | Positive Examples | Usage | | -----|-------------|-------------------|-------| | even| Return true if target is an even number | E.g. 0, 2, 4, 6 | HayTypes.number.even | | odd| Return true if target is an odd number | E.g. 1, 3, 5 | HayTypes.number.odd | | positive| Return true if target is a positive number | E.g. 1, 2, 3 | HayTypes.number.positive | | negative| Return true if target is a negative number | E.g. -1, -2, -3 | HayTypes.number.negative |

HayTypes.string

| Type | Description | Positive Examples | Usage | | -----|-------------|-------------------|-------| | min(input) | Return true if at least of input length | E.g. '123', '1234', '12345' | HayTypes.string.min(3) | | max(input) | Return true if at most of input length | E.g. '1', '12', '123' | HayTypes.string.max(3) |

HayTypes.array | Type | Description | Positive Examples | Usage | | -----|-------------|-------------------|-------| | withFunc | Takes in a function which the function needs to return the HayType each time it is called when checking through the array. | function(obj, index) { return ([HayTypes.number][index])(obj); } | HayTypes.array.withFunc(function(obj, index) { return ([HayTypes.number][index])(obj); }) | | withGeneratorFunc | Takes in a generator function which the function needs to return the HayType each time it is called when checking through the array. | function*() { while(true) { yield HayTypes.number; } } | HayTypes.array.withGeneratorFunc(function*() { while(true) { yield HayTypes.number; }}) | | uniqueItems | Return true if item is an array with all unique items. | [1,2,3,4,5] | HayTypes.array.uniqueItems |

    HayTypes.arrayOf | Type | Description | Positive Examples | Usage | | -----|-------------|-------------------|-------| | itemsOfEqualLength | Return true if all items are array of equal length. | [[], [], []] | HayTypes.arrayOf.itemsOfEqualLength([[], [], []])) |