accurized
Verify the validity and accuracy of data as it enters your system.
Last updated 3 years ago by bitbutcher .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install accurized 
SYNC missed versions from official npm registry.

Accurized

Verify the validity and accuracy of data as it enters your system.

Getting Started

Install Accurized:

npm install accurized --save

Overview

Accurized, in its simplest form, is a fluent interface wrapper around the validator module. In addition it includes connect/express middleware builders for validating url-encoded forms and JSON data submissions.

Examples

Field Validation:

accurized = require 'accurized'

validate = accurized.field('must be a valid email address').trim().email().as 'string'

validate 'user@domain.com',
  (value) ->
    assert value is 'user@domain.com'
  (error) ->
    assert false

validate '   user@domain.com  ',
  (value) ->
    assert value is 'user@domain.com'
  (error) ->
    assert false

validate 'monkeys',
  (value) ->
    assert false
  (error) ->
    assert error is 'must be a valid email address'

JSON Validation:

express = require 'express'
accurized = require 'accurized'
body = require 'body-parser'
app = express()
app.use body.json()
app.post '/events',
  accurized.data (json, req, res, next) ->
    json.field('name', 'A name between 3 and 33 characters long is required.')
      .trim().length(3, 33)
    json.field('state', "The state must be one of 'visible', 'hidden' or 'deleted'.")
      .trim().in(['visible', 'hidden', 'deleted'])
    start = json.field('time.start', 'The start time, if present, must be an iso8601 formatted datetime.')
      .trim().optional().date().as 'date'
    json.field('time.end', 'The end time, if present, must be an iso8601 formatted datetime occurring after the start time.')
      .trim().optional().after(start.value()).as 'date'
    # if any of the above fail the built middleware will render a response
    # with a status code of 422 and a human and machine readable JSON body
    # describing the invalid field and their issues
  (res, res, next) ->
    # operate on the body knowing that all of the above transformations,
    # validations and type coercions have been performed successfully

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.

Release History

(Nothing yet)

Current Tags

  • 0.4.6                                ...           latest (3 years ago)

14 Versions

  • 0.4.6                                ...           3 years ago
  • 0.4.5                                ...           4 years ago
  • 0.4.4                                ...           4 years ago
  • 0.4.3                                ...           4 years ago
  • 0.4.2                                ...           5 years ago
  • 0.4.1                                ...           5 years ago
  • 0.4.0                                ...           5 years ago
  • 0.3.0                                ...           5 years ago
  • 0.2.1                                ...           5 years ago
  • 0.2.0                                ...           5 years ago
  • 0.1.2                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
  • 0.0.1                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 1
Dependencies (4)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |