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

mini-type-assert

v0.1.2

Published

Concise type assertions like a<map<fn:s>>

Downloads

7

Readme

mini-type-assert

Concise type assertions like a<map<fn:s>>. Expressions are parsed just once: it generates functions and caches them. Supports the types of kind-of and has short aliases for most.

npm status Dependency status

example

const t = require('mini-type-assert')

class Example {
  constructor(age, mixed, words, store, opts = {}) {
    this.age = t(age, 'n', 'age')
    this.mixed = t(mixed, 'a<s|n>', 'mixed')
    this.store = t(store, 'map<fn:re>', 'store')

    // Spaces are allowed
    this.words = t(words, 'a < /^[a-z]+$/ >', 'words')

    // Or use placeholders
    this.words = t(words, 'a<$>', 'words', /^[a-z]+$/)

    // Throw if a is defined and not a boolean
    const { a = false } = t(opts, 'o<bool>', 'opts')
  }
}

// Instantiate maps with key-value pairs
const goodboy = new Map([ [function(){}, /a/] ])
const badboy = new Map([ ['not a function', /a/] ])

// Okay
new Example(27, [1, 'a'], ['beep'], goodboy, { a: true })

// Throws
new Example('bad', [null], ['BEEP'], badboy, { a: 0 })

decorator

If you like ES7 decorators, check out mini-type-decorator.

const t = require('mini-type-decorator')

@t('a<s>', ['n', (n) => n <= 10], 'o<b>')
class Example {
  constructor(tags, grade, flags = {}) {
    this.tags = tags
  }

  @t('s')
  say(what) {
    console.log(what)
  }
}

t(value, assertion, name, ...placeholders)

The first three arguments are required. Throws if value does not pass assertion. Otherwise, returns value. The name will be used in the error message.

assertions

If assertion is a string or regular expression, it will be treated as a type expression (see below). If it's a function, it will receive the value and should return false if the value is invalid. A boolean assertion works like assert(assertion === true). If assertion is an array, each element must pass assertion. For example, to assert that an argument is a number and greater than two: t(arg, ['n', (v) => v > 2 ], 'arg').

type expressions

  • Aliases: a<s|f> is arr<str|fn> is array<string|function>. See the full list.
  • Member types: a<n> (an array of numbers). Note that the entire iterable (array, object, map, ..) will be traversed, so use it wisely.
  • Member key types: map<r:n> (a Map with regular expressions for keys and numbers for values). Again, traversed entirely. Key types are ignored for arrays (can only be numbers) and objects (can only be strings).
  • OR: n|s (a number or string)
  • Regular expressions:
    • /\d/ (a string containing at least one number)
    • a < /^x$/i > (an array containing "x" or "X" strings)
    • map < /^[a-z]+$/ : /^[a-z]+$/ > (a Map with lowercase strings for both keys and values)
  • Negation: !fn (anything but a function)
  • Whitespace: s | a is s|a. Except within regular expressions, spaces are ignored.
  • Operator precedence: s|a<n|b> (a string, or an array containing numbers or booleans)
  • Placeholders: t(1, '$|$', 'arg', 's', 'n') is the same as t(1, 's|n', 'arg')

install

With npm do:

npm install mini-type-assert --save

license

MIT © Vincent Weevers