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

hype-type

v0.3.1

Published

JavaScript library for maintaining value types

Downloads

10

Readme

hype-type

npm version

Install

npm i hype-type

Usage

Using hype-type you can check the type of value using built-in library types or your own ones

'use strict'

const { Type } = require('hype-type');

Type.Date.is(new Date()); // true

const integer = new Type(value => 
  Type.Number.is(value) &&
  value % 1 === 0
);

integer.is(123); // true
integer.is(12.3); // false

API

Library exports Type class with assigned built-in types.

Type class

Type instances are created by defining type's its constraint, extending an existing type or wrapping a class:


/**
 * Simple number type
 */
const number = new Type(value => typeof value === 'number');
number.is(10); // true
number.is('10'); // false

/**
 * Extending an existing type
 */
const integer = Type.extend(number, value => value % 1 === 0);
integer.is(10); // true
integer.is(10.1); // false

/**
 * Create a type from a class
 */
const map = Type.from(Map);
map.is(new Map()); // true
map.is({}); // false

Type methods:

  • is(value) - check whether the value accepts type's constraint

Type static methods:

  • extend(type, constraint) - create a new type, inheriting all parent's constraints
  • from(class) - create a new type, which values are instances of class
  • union(...types) - create a TypeUnion instance from given types

TypeUnion class

TypeUnion extends Type class, so it also has an is method.

TypeUnion methods:

  • of(value) - return the type of value, if value accepts some from TypeUnion types.

const unionType = Type.union(Type.Number, Type.String);
unionType.is(123); // true
unionType.is('123'); // true
unionType.is({}); // false

unionType.of(123); // Type.Number
unionType.of('123'); // Type.String
unionType.of({}); // undefined

Schema class

Schema class is useful for defining object property types


const { Type, Schema } = require('hype-type');

const person = new Schema({
  id: Type.Number,
  name: Type.Stirng,
  born: Type.Date,
});

person.is({
  id: 1,
  name: 'Alexander',
  born: new Date(),
}); // true

Schema extends Type class, so it has the same methods.

You can also define optional properties using [] syntax:


const person = new Schema({
  id: Type.Number,
  name: Type.String,
  born: [Type.Date], // optional
});

person.is({
  id: 1,
  name: 'Alexander',
}); // true

person.is({
  name: 'Alexander',
}); // false, required property `id` is missing