tassert

High quality runtime assertions for Typescript

Usage no npm install needed!

<script type="module">
  import tassert from 'https://cdn.skypack.dev/tassert';
</script>

README

tassert Build Status npm mit

High quality runtime assertions for Typescript

Alpha - ready for feedback

Installation

npm install -S tassert

Usage

import t, {boolean, literal, number, or, string} from 'tassert'

t(number, 42)
t(string, 'foo')
t(or(boolean, number, string), 999)
t(literal([1,2,3]), [1,2]) // Error!

Features

  • Native types
    • Array
      • Array<any>
      • Array<A>
    • ArrayBuffer
    • Boolean
    • Buffer
    • Date
    • Error
    • Function
    • Map
      • Map<any, any>
      • Map<A, B>
    • NaN
    • Null
    • Number
    • Object
      • Object<any, any>
      • Object<A, B>
    • RegExp
    • Set
      • Set<any>
      • Set<A>
    • String
    • Symbol
    • TypedArray
    • Undefined
    • WeakMap
      • WeakMap<any, any>
      • WeakMap<A, B>
    • WeakSet
      • WeakSet<any>
      • WeakSet<A>
  • Constructors (tassert.instanceOf(Foo))
  • Literals
    • Shallow (tassert.literal(42, false))
    • Deep (tassert.literal(42))
  • Logic
    • and (tassert.and(tassert.literal(42), tassert.number))
    • or (tassert.or(tassert.string, tassert.number, tassert.array))
    • not (tassert.or(tassert.string, not(tassert.string('foo'))))
    • xor (tassert.xor(tassert.literal(42), tassert.number))
  • Comparators
    • ==
    • >
    • <
    • >=
    • <=
    • :> (Superset of)
    • <: (Subset of)
    • ~= (Structurally equal)

Tests

npm test

Building

npm run build

Hacking

npm run watch & npm run tdd