Skip to content

Latest commit

 

History

History
50 lines (41 loc) · 1.16 KB

.verb.md

File metadata and controls

50 lines (41 loc) · 1.16 KB

Usage

var schema = require('{%= name %}');

Example

This is a basic example schema for normalizing and validating fields on package.json (a full version of this will be available on [normalize-pkg][] when complete):

var fs = require('fs');
var isObject = require('isobject');
var Schema = require('map-schema');

// create a schema
var schema = new Schema()
  .field('name', 'string')
  .field('description', 'string')
  .field('repository', ['object', 'string'], {
    normalize: function(val) {
      return isObject(val) ? val.url : val;
    }
  })
  .field('main', 'string', {
    validate: function(filepath) {
      return fs.existsSync(filepath);
    }
  })
  .field('version', 'string', {
    default: '0.1.0'
  })
  .field('license', 'string', {
    default: 'MIT'
  })

var pkg = require('./package');
// normalize an object
console.log(schema.normalize(pkg));
// validation errors array
console.log(schema.errors);

Errors

Validation errors are exposed on schema.errors. Error reporting is pretty basic right now but I plan to implement something better soon.

API

{%= apidocs("index.js") %} {%= apidocs("lib/*.js", {auto: true}) %}