开发者社区> 镜像站> NPM> muxrpc-validation
muxrpc-validation
Validation library for muxrpc apis
Last updated 2 years ago by dominictarr .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install muxrpc-validation 
SYNC missed versions from official npm registry.

muxrpc validation

Validation library for muxrpc apis.

// create validator library
var valid = require('muxrpc-validation')({
  queryOpts: function (v) {
    if (v.reverse && typeof v.reverse != 'boolean')
      return new TypeError('opts.reverse must be a bool')
  }
})

// api manifest
var manifest = {
  usage: 'sync',
  get:   'async',
  add:   'async',
  list:  'source'
}

// api definition - wrap the functions in the validators
var api = {
  usage:   valid.sync(usage, 'string|boolean'), // multiple types
  get:     valid.async(get, 'string'),
  add:     valid.async(add, ['string'], ['string', 'object']), // multiple signatures
  put:     valid.async(add, {cbOptional: true}, 'string'), // async method works without a cb
  list:    valid.source(list, 'queryOpts?') // optional param
}

function usage (cmd) {
  // ...
}
function get (key, cb) {
  // ...
}
function add (key, value, cb) {
  if (typeof value == 'function') {
    // handle (value, cb)
    value = key
    key = value.key
    cb = value
  }
  // ...
}
function list (opts) {
  opts = opts || {}
  // ...
}

Current Tags

  • 3.0.2                                ...           latest (2 years ago)

11 Versions

  • 3.0.2                                ...           2 years ago
  • 3.0.1                                ...           2 years ago
  • 3.0.0                                ...           5 years ago
  • 2.0.1                                ...           5 years ago
  • 2.0.0                                ...           5 years ago
  • 1.0.5                                ...           5 years ago
  • 1.0.4                                ...           5 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago