tassert
High quality runtime assertions for Typescript
Alpha - ready for feedback
Installation
npm install -S tassert
Usage
tnumber, 42tstring, 'foo'torboolean, number, string, 999tliteral, // 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)
)
- Shallow (
- 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