Latest version : 0.4.6

 Last updated on 2017-04-19T18:52:40.985Z

 Keywords : fluent, accurize, accuracy, accurate, validate, validator, validation, data, field, form, json, express, middleware

 Downloads :

  • 187 in Last Month

 Links :


No examples found for this package



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

Getting Started

Install Accurized:

npm install accurized --save


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.


Field Validation:

accurized = require 'accurized'

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

validate '',
  (value) ->
    assert value is ''
  (error) ->
    assert false

validate '  ',
  (value) ->
    assert value is ''
  (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() '/events', (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


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)