Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/codemix/modeling
Fast and flexible data models for node.js and the browser.
https://github.com/codemix/modeling
Last synced: 5 days ago
JSON representation
Fast and flexible data models for node.js and the browser.
- Host: GitHub
- URL: https://github.com/codemix/modeling
- Owner: codemix
- License: mit
- Created: 2014-06-05T12:48:58.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-11-30T20:05:44.000Z (almost 10 years ago)
- Last Synced: 2024-10-03T00:14:35.339Z (about 1 month ago)
- Language: JavaScript
- Size: 219 KB
- Stars: 15
- Watchers: 6
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-starred - codemix/modeling - Fast and flexible data models for node.js and the browser. (others)
README
# Modeling
[![Build Status](https://travis-ci.org/codemix/modeling.svg?branch=master)](https://travis-ci.org/codemix/modeling)
# Usage
```js
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](https://npmjs.org/package/modeling):
npm install --save modeling
or [bower](http://bower.io/search/?q=modeling):
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](LICENSE.md).