0.3.0 • Published 8 years ago

micromanage v0.3.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

Micromanage

This is a proof of concept

A utility for generating object factories validated by JSON schemas.

Micromanage uses jjv to parse JSON Schemas.

Why

Vanilla JavaScript objects are easy to work with. They behave as expected; they contain no implicit API. They can pass freely through most code without interoperability hiccups.

However it can be hard to determine their shape, set default values, and validate them.

This library provides a thin layer over the JSON Schema Draft 4 specification to make it easier to manipulate, reason about, and validate client-side data.

Specifically, it aims to provide an answer for:

  1. Data validation
  2. Structural consistency
  3. Test scaffolding (randomly generate content based on a schema)

Usage

var Record = require('micromanage').Record

var Cat = Record({
    title: 'Cat',
    properties: {
        species: {
            type: 'string',
            default: 'feline'
        },
        name: {
            type: 'string'
        }
    },
    required: [ 'name' ]
})

// Created an object based on the Cat schema.
var kitten = Cat({ name: 'Felix' }) // => { name: 'felix', species: 'feline' }

// Update a record. This is non-destructive. Returns a new Cat object
var copyCat = Cat.update(kitten, { name: 'Carl' }) // => { name: 'Carl', species: 'feline'}

// Validate a record
var isValid = Cat.validate({}) // { errors: { name: 'required' } }

Reference

0.3.0

8 years ago

0.2.0

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago