# ag-types

> Arbitrary data structure validation

Latest version **0.3.1** (published 2015-04-02) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install ag-types
pnpm add ag-types
yarn add ag-types
bun add ag-types
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2015-04-02 |
| First published | 2014-07-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Eevert Saukkokoski |
| Maintainers | ezku, ag-hostmaster |
| Keywords | validate, validator, type |

## Links

- npm: https://www.npmjs.com/package/ag-types
- Repository: https://github.com/AppGyver/ag-types
- Issues: https://github.com/AppGyver/ag-types/issues
- npm.io page: https://npm.io/package/ag-types

## Dependencies (2)

- [lodash-node](https://npm.io/package/lodash-node.md) 3.6.0
- [data.validation](https://npm.io/package/data.validation.md) 1.3.0

## Alternatives

- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 0.3.1 (latest) — 2015-04-02
- 0.3.0 — 2015-04-02
- 0.2.6 — 2014-12-02
- 0.2.5 — 2014-11-17
- 0.2.4 — 2014-10-16
- 0.2.3 — 2014-10-15
- 0.2.2 — 2014-10-15
- 0.2.1 — 2014-10-15
- 0.2.0 — 2014-10-15
- 0.1.7 — 2014-08-28
- 0.1.6 — 2014-08-14
- 0.1.5 — 2014-07-11
- 0.1.2 — 2014-07-07
- 0.1.1 — 2014-07-07
- 0.1.0 — 2014-07-07

## README

ag-types - arbitrary data structure validation for Javascript
========

[![Build Status](http://img.shields.io/travis/AppGyver/ag-types/master.svg)](https://travis-ci.org/AppGyver/ag-types)
[![NPM version](http://img.shields.io/npm/v/ag-types.svg)](https://www.npmjs.org/package/ag-types)
[![Dependency Status](http://img.shields.io/david/AppGyver/ag-types.svg)](https://david-dm.org/AppGyver/ag-types)
[![Coverage Status](https://img.shields.io/coveralls/AppGyver/ag-types.svg)](https://coveralls.io/r/AppGyver/ag-types)

You've got incoming JSON data that you'd like to access using Javascript, but you can't be sure its structure matches what you expect. `ag-types` allows you to validate the structure of the input graph before you crash and burn on a `TypeError: 'undefined' is not an object`.


## Installation

    npm install ag-types


## Usage

Examples in Coffeescript.


### Describe your type

```coffeescript
{ Object, String, Optional, Map, Any } = require 'ag-types'
RequestType = Object {
  url: String
  method: String
  params: Optional Map Any
}
```

Construct a type validator by simply mirroring the structure of what you want.


### Validate input data against the type

```coffeescript
input = {
  url: 'http://example.com'
}
RequestType(input)
```

Your validator is a function that returns a [data.validation](https://github.com/folktale/data.validation).


### Continue off the validation result

```coffeescript
RequestType(input).fold(
  (errors) -> console.log "This doesn't look like a valid request: ", errors
  (request) -> doRequest request
)
```

If an error occurs, the errors object will hold details of what went wrong. Otherwise you're good to go with the data.


## Development

    npm install
    grunt test watch:test --force

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