An open API service indexing awesome lists of open source software.

https://github.com/bcherny/tassert

High quality runtime assertions for Typescript
https://github.com/bcherny/tassert

typescript

Last synced: 7 months ago
JSON representation

High quality runtime assertions for Typescript

Awesome Lists containing this project

README

          

# tassert [![Build Status][build]](https://circleci.com/gh/bcherny/tassert) [![npm]](https://www.npmjs.com/package/tassert) [![mit]](https://opensource.org/licenses/MIT)

[build]: https://img.shields.io/circleci/project/bcherny/tassert.svg?branch=master&style=flat-square
[npm]: https://img.shields.io/npm/v/tassert.svg?style=flat-square
[mit]: https://img.shields.io/npm/l/tassert.svg?style=flat-square

> High quality runtime assertions for Typescript

**Alpha - ready for feedback**

## Installation

`npm install -S tassert`

## Usage

```ts
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`
- [x] `Array`
- [ ] `Array`
- [x] `ArrayBuffer`
- [x] `Boolean`
- [x] `Buffer`
- [x] `Date`
- [x] `Error`
- [x] `Function`
- [ ] `Map`
- [ ] `Map`
- [ ] `Map
`
- [x] `NaN`
- [x] `Null`
- [x] `Number`
- [ ] `Object`
- [x] `Object`
- [ ] `Object
`
- [x] `RegExp`
- [ ] `Set`
- [ ] `Set`
- [ ] `Set
`
- [x] `String`
- [x] `Symbol`
- [x] `TypedArray`
- [x] `Undefined`
- [ ] `WeakMap`
- [ ] `WeakMap`
- [ ] `WeakMap
`
- [ ] `WeakSet`
- [ ] `WeakSet`
- [ ] `WeakSet
`
- [x] Constructors (`tassert.instanceOf(Foo)`)
- [x] Literals
- [x] Shallow (`tassert.literal(42, false)`)
- [x] Deep (`tassert.literal(42)`)
- [x] Logic
- [x] `and` (`tassert.and(tassert.literal(42), tassert.number)`)
- [x] `or` (`tassert.or(tassert.string, tassert.number, tassert.array)`)
- [x] `not` (`tassert.or(tassert.string, not(tassert.string('foo')))`)
- [x] `xor` (`tassert.xor(tassert.literal(42), tassert.number)`)
- [ ] Comparators
- [x] ==
- [ ] >
- [ ] <
- [ ] >=
- [ ] <=
- [ ] :> (Superset of)
- [ ] <: (Subset of)
- [ ] ~= (Structurally equal)

## Tests

`npm test`

## Building

`npm run build`

## Hacking

`npm run watch & npm run tdd`