High quality runtime assertions for Typescript
Alpha - ready for feedback
npm install -S tassert
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!
- 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)
npm test
npm run build
npm run watch & npm run tdd