# izz-ts

> Easy type guards for TypeScript

Latest version **0.2.2** (published 2017-06-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install izz-ts
pnpm add izz-ts
yarn add izz-ts
bun add izz-ts
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2017-06-22 |
| First published | 2017-06-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Jason Goldberger |
| Maintainers | elbow-jason |

## Links

- npm: https://www.npmjs.com/package/izz-ts
- Repository: https://github.com/elbow-jason/izz-ts
- Homepage: https://github.com/elbow-jason/izz-ts#readme
- Issues: https://github.com/elbow-jason/izz-ts/issues
- npm.io page: https://npm.io/package/izz-ts

## Recent versions

- 0.2.2 (latest) — 2017-06-22
- 0.2.1 — 2017-06-21
- 0.2.0 — 2017-06-21
- 0.1.7 — 2017-06-17
- 0.1.6 — 2017-06-17
- 0.1.4 — 2017-06-17
- 0.1.3 — 2017-06-16
- 0.1.2 — 2017-06-16
- 0.1.1 — 2017-06-16
- 0.1.0 — 2017-06-16

## README

[![Build Status](https://travis-ci.org/elbow-jason/izz-ts.svg?branch=master)](https://travis-ci.org/elbow-jason/izz-ts)

# izz-ts 
A TypeScript Guard Type Checker

## Install

`npm install --save izz-ts`

## Example

### Code

```typescript
import * as izz from 'izz-ts'

export class Sale {
  key:                       string = ''
  completing_party_name:     string = ''
  completing_party_address:  string = ''
  completing_party_phone:    string = ''
  down_payment:     (null | number) = null
  sale_price:       (null | number) = null

  static paramsValidator = izz.object({
    key:                       izz.string,
    completing_party_name:     izz.string,
    completing_party_address:  izz.string,
    completing_party_phone:    izz.string,
    sale_price:                izz.number,
    down_payment:              izz.number,
  })

  static isValidJSON(data: any): data is Sale {
    return Sale.paramsValidator.isValid(data)
  }

  static fromJSON(data: any): (Sale | never) {
    if (Sale.isValidJSON(data)) {
      return new Sale(data)
    } else {
      let val = new izz.DataValidator('SaleJSON', Sale.paramsValidator, data)
      console.groupCollapsed('Invalid Sale JSON')
      console.log('data', data)
      console.log('errors', val.errors)
      console.groupEnd()
      throw new Error(`Invalid Sale JSON`)
    }
  }

  constructor(params: (Sale | null) = null) {
    if (params) {
      this.key                      = params.key
      this.completing_party_name    = params.completing_party_name
      this.completing_party_address = params.completing_party_address
      this.completing_party_phone   = params.completing_party_phone
      this.sale_price               = params.sale_price
      this.down_payment             = params.down_payment
    }
  }
}
```

### Logged Invalid Data

![sale_errors.png](images/sale_errors.png)

---
_Source: https://npm.io/package/izz-ts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
