This project aims to bring some level of data/type safety to NodeJS whilst allowing us to define clean data models.
Check out the tests for a clear picture of how powerful this is.
var Modeler = require("../Modeler.js");
var className = 'MyClassName';
var ThisClass = function(json) {
this.toString = function() {
return this.PropertyName+" "+this.SomeOtherProperty;
};
Modeler.extend(className, {
[PropertyName]: {
type: "SomeOtherClass",
default: { DefaultValue },
required: true,
filter: {
{ trim: true },
{ replace: ['test', 'TEST'] },
{ encode: 'base64' / 'json' / 'url' },
{ decode: 'base64' / 'json' / 'url' },
{ capitalise: true },
{ toMoney: true },
{ toUpperCase: true },
{ toLowerCase: true }
},
filter: function(v) {
...
return v;
},
validation: {
isIn: ['list', 'of', 'values'],
minlength: 2,
maxlength: 4,
before: new Date(),
after: new Date(),
regex: /regex/,
looksLike: 'postcode' / 'email',
min: 1,
max: 100
},
validation: function(v) {
...
return true / false;
},
mask: Modeler.GET | Modeler.SET | Modeler.HIDDEN | Modeler.ARRAY
},
[NextProperty]: {
.....
}, this, json);
};
module.exports = ThisClass;
Modeler.register(ThisClass, className);