Skip to content

juaniyyoo/pi-model

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM version Build Status Coverage Status Dependency Status

PiModel

PiModel is a simple data model representation that allows data validation and some basic features.

It is aimed to be used in a more organized data accesses (repository, datamapper, datasource, etc.).

Install

npm install pi-model

Usage

// New model definition 
var ModelBuilder = require('pi-model'),
    User         = new ModelBuilder({
      'name' : 'UserModel'
    });

// Model usage
var myUser = new User({
  'firstName' : 'John',
  'lastName'  : 'Doe'
});

Builder options

The model builder accepts the following options :

{
  'name' : String,
  'description' : Object,
  'validator' : Function
}
  • name : String used to define the model
  • description : Object describing custom information of the model
  • validator : Instance used to validate data over the schema

Validator

You can use pi-validator-tv4 if needed. It is a simple encapsulation of tv4 (validation with JSON schema).

Create a custom validator

If you need to create your own validator, you can base extend pi-validator.

It is an abstraction of the validator.

About

A model basis with schema validation

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%