ag-types
Arbitrary data structure validation
Last updated 5 years ago by ezku .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install ag-types 
SYNC missed versions from official npm registry.

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

{ 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

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

Current Tags

  • 0.3.1                                ...           latest (5 years ago)

15 Versions

  • 0.3.1                                ...           5 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.6                                ...           6 years ago
  • 0.2.5                                ...           6 years ago
  • 0.2.4                                ...           6 years ago
  • 0.2.3                                ...           6 years ago
  • 0.2.2                                ...           6 years ago
  • 0.2.1                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.7                                ...           6 years ago
  • 0.1.6                                ...           6 years ago
  • 0.1.5                                ...           6 years ago
  • 0.1.2                                ...           6 years ago
  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (11)

Copyright 2014 - 2017 © taobao.org |