Skip to content

JonDotsoy/vapi.js

Repository files navigation

vapi

Package Quality npm

A javascript library that helps you create models in your applications.

Goals to vapi 🐇

  • Define a model.
  • [ ]

Quick Start

Using npm:

$ npm install --save vapi

In Node.js:

// /app/models/MyModel.js
const {Model} = require('vapi')

Documentation

Quick Examples

class Person extends Model {}
// Define properties to Person model.
Person.defineProperty('first', { alias: 'name' })
Person.defineProperty('name', {
    transform: require('lodash/toLower')
})

class User extends Model {}
// Define properties to User model.
User.defineProperties({
    'username': {
        transform: require('lodash/toLower')
    },
    'password': {
        validation: (v) => /^[a-z|0-9]{9,15}$/.test(v)
    },
    'person': {}
})

// Create an instance of the User model.
const cat = new User({
    username: 'UserA',
    password: '1234', // Bad Password
    person: new Person({
        name: 'Julio'
    })
})

// Validation
if (cat.isValid()) {
    // you code if is valid.
} else {
    // you code of is not valid.
}

// End Cat state
// cat => 
// {
//   "username": "usera",
//   "password": "1234",
//   "person": {
//     "first": "julio",
//     "name": "julio"
//   }
// }

License

This project is under a MIT License.

About

A javascript library that helps you create models in your applications.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published