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

microtype

v0.0.8

Published

A tiny type thingy for javascript

Readme

MicroType

(minitype)

A small typecheck thing.

Now there are functions __$$ and _$$: they return true if all constraints are satisfied, otherwise false. (_$ and __$ depend on __$$).

The general syntax is:


__$(errorHandler, constraints, value0, constraint0, value1, constraint1, ..., func);
// see actual implementation for defaults in source
// Defaults are in '_$'.

// Where errorHandler is:
// (gets called when any constraint is not satisfied)
Function = () => ... // Throw a TypeError

// Where 'constraints' is:
Object = {
	type: String => ..., // Checks type. (uses typeof)
	func: Function => ..., // A filter function (must return true for the constraint to be satisfied)
	inst: Object => ..., // Checks is value is an instance of specified type (uses instanceof)
}

// Where 'constraint' is:
// 'constraints' define possible fields of 'constraint'.
// (All fields are optional)
Object

// Where value is:
Object

// Where func is:
// (gets called when all constraints are satisfied)
Function

Example:


const { _$ } = require("microtype");

const test = (a, b) => _$(a, {inst: Array}, b, {type: "string", func: x => x ? x.startsWith("Hello") : false}, () => {
	// here, a is an array, b is a string.
	console.log(a[0], b);
});

test([12, 53], "Hello!"); // -> 12 Hello!
test(12, "Hello!"); // -> TypeError!
test([12, 56], "Bye!"); // -> TypeError!
test("hello", null); // -> TypeError

Changelog

  • 0.0.8: [14th of September, 2020]: Added _$$ and __$$. Also fixed some typos in README.md.

  • 0.0.7: [14th of September, 2020]: Internal changes. Moved constraint definitions to a separate constant.

  • 0.0.6: [14th of September, 2020]: Fixed README.md Dates were incorrect, Some example issues.

  • 0.0.5: [13th of September, 2020]: Added Changelog. You are looking at it right now.

  • 0.0.4: [13th of September, 2020]: Moved constraint definition to _$. Now you can have custom constraint types (by using __$)

  • 0.0.3 [12th of September, 2020]: API change. Added support for functions as constraints. Looks like this: _$(a, {type: "string"}, b, {func: x => x < 10}, () => "a isd a string, b is less than 10")

  • 0.0.2 [10th of September, 2020]: Added README.md

  • 0.0.1 [10th of September, 2020]: Initial version. Only support type checking: like so _$(a, "string", b, "number", () => "a is a string, b is a number")