modeling 14

Fast and flexible data models for node.js and the browser.

codemix/modeling

Written in JavaScript by 1 contributor

Contribute

Need Support?


we offer maintenance, support and development services for all our open source projects.

Contact Us

Modeling

Build Status

Usage

var Modeling = require('modeling');

var Thing = Modeling("Thing", {
  name: {
    label: 'Name',
    description: 'The name of the item',
    type: 'string',
    rules: [
      ['required']
    ]
  },
  description: {
    label: 'Description',
    description: 'A short description of the item.',
    type: 'string',
    rules: [
      {name: 'length', max: 255}
    ]
  },
  url: {
    label: 'URL',
    description: 'A URL identifiying the item.',
    type: 'string',
    rules: [
      ['url']
    ]
  }
});

var Person = Thing.extend("Person", {
  dateOfBirth: {
    label: 'Date of Birth',
    description: "The person's date of birth.",
    type: Date,
    rules: [
      ['date']
    ]
  },
  age: {
    label: 'Age',
    description: "The person's age.",
    type: Number,
    get: function () {
      var birthday = this.dateOfBirth;
      if (!birthday) {
        return false;
      }
      var ageDifMs = Date.now() - birthday.getTime();
      var ageDate = new Date(ageDifMs); // miliseconds from epoch
      return Math.abs(ageDate.getFullYear() - 1970);
    }
  }
});

var person = new Person({
  name: 'Bob',
  url: 'http://codemix.com/',
  dateOfBirth: '1980-01-01'
});

console.log(person.age);

console.log(JSON.stringify(person, null, 2));

Installation

Via npm:

npm install --save modeling

or bower:

bower install --save modeling

Running the tests

First, npm install, then npm test. Code coverage generated with npm run coverage.

License

MIT, see LICENSE.md.





44 other JavaScript projects


fast.jsJavaScript 2930

Faster user-land reimplementations for several common builtin native JavaScript functions.

babel-plugin-typecheckJavaScript 823

Static and runtime type checking for JavaScript in the form of a Babel plugin.

babel-plugin-closure-eliminationJavaScript 223

A Babel plugin which eliminates closures from your JavaScript wherever possible.

orientoJavaScript 212

Former official node.js driver for OrientDB. Fast, lightweight, uses the binary protocol. Now deprecated.

babel-plugin-macrosJavaScript 184

Hygienic, non-syntactic macros for JavaScript via a Babel plugin.

htmlingJavaScript 167

Polymer / HTML5 templating syntax for node.js

babel-plugin-contractsJavaScript 128

Design by Contract for JavaScript via a Babel plugin.

YiiBlocksJavaScript 70

A set of building blocks that provide common functions for Yii web applications

contractualJavaScript 52

Unobtrusive, backwards compatible, syntactic sugar for Design by contract in JavaScript.

gitignore-parserJavaScript 34

A simple .gitignore parser for node.js

binary-protocolJavaScript 13

Easy, fast, writers and readers for implementing custom binary protocols in node.js.

YiiJSJavaScript 11

A port of the Yii PHP framework to JavaScript

url-routeJavaScript 10

Web component providing URL routing

validatingJavaScript 10

Quick and easy validators for node.js and the browser.

babel-plugin-traceJavaScript 6

This is a Babel plugin which adds a straightforward, declarative syntax for adding debug logging to JavaScript applications.

geonames-importerJavaScript 6

Imports geonames data into elasticsearch

mallocJavaScript 6

Simple malloc() & free() implementation for node.js, built on top of array buffers.

classingJavaScript 5

Fluent classes for node.js and the browser.

castingJavaScript 5

Tiny type casting library for node.js and the browser.

dispatchingJavaScript 5

Tiny routing / dispatch library for node and the browser.

atomicbuffersJavaScript 5

Atomic `readInt32()`, `writeInt32()`, `readUInt32()` and `writeUInt32()` for node.js buffers.

mimingJavaScript 3

Processing and formatting for various mime types.

oriento-query-builderJavaScript 1

A standalone query builder for OrientDB, designed for node.js/io.js and the browser.

bootstrap-tooltipJavaScript 1

Twitter Bootstrap Tooltip plugin packaged for component.js instead of bower

obligationsJavaScript 1

Tiny JavaScript library for preconditions and postconditions, intended for use with Contractual.

bootstrap-transitionJavaScript 1

Twitter Bootstrap Transition plugin packaged for component.js instead of bower

cover.jsJavaScript

JQuery plugin for covering/uncovering DOM elements

webrtc-playgroundJavaScript

WebRTC sample code. For testing purposes only.

bootstrap-tabJavaScript

Twitter Bootstrap Tab plugin packaged for component.js instead of bower

bootstrap-scrollspyJavaScript

Twitter Bootstrap Scrollspy plugin packaged for component.js instead of bower

bootstrap-dropdownJavaScript

Twitter Bootstrap Dropdown plugin packaged for component.js instead of bower

bootstrap-carouselJavaScript

Twitter Bootstrap Carousel plugin packaged for component.js instead of bower

tabinetJavaScript

A popular romanian card game

flex-basicJavaScript

A basic Flex App setup for video broadcasting

bootstrap-popoverJavaScript

Twitter Bootstrap Popover plugin packaged for component.js instead of bower

bootstrap-buttonJavaScript

Twitter Bootstrap Button plugin packaged for component.js instead of bower

bootstrap-alertJavaScript

Twitter Bootstrap Alert plugin packaged for component.js instead of bower

bootstrap-affixJavaScript

Twitter Bootstrap Affix plugin packaged for component.js instead of bower

bootstrap-typeaheadJavaScript

Twitter Bootstrap Typeahead plugin packaged for component.js instead of bower

bootstrap-collapseJavaScript

Twitter Bootstrap Collapse plugin packaged for component.js instead of bower

bootstrap-componentJavaScript

Twitter Bootstrap packaged for component.js instead of bower

ProductManagerJavaScript

A Sample CRUD application structured by Backbone js and backed by a node restfull api.

elevatorJavaScript

http://samsonradu.github.io/elevator/

bootstrap-modalJavaScript

Twitter Bootstrap Modal plugin packaged for component.js instead of bower