This package has been deprecated

Author message:

This library has been deprecated.

ag-types

0.3.1 • Public • Published

ag-types - arbitrary data structure validation for Javascript

Build Status NPM version Dependency Status Coverage Status

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

{ ObjectStringOptionalMapAny } = 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

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

Your validator is a function that returns a data.validation.

Continue off the validation result

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

Readme

Keywords

Package Sidebar

Install

npm i ag-types

Weekly Downloads

11

Version

0.3.1

License

MIT

Last publish

Collaborators

  • ag-hostmaster
  • ezku