property-modeler
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -121,4 +121,5 @@ "use strict"; | ||
(newValue.__type == propertyType) ) ); | ||
if ((propertyType == "date") && (newValue instanceof Date)) validType = true; | ||
var passedValidation = validateFunction.call(obj, newValue); | ||
if ( (propertyType && validType && passedValidation) || passedValidation) { | ||
if ( (propertyType && validType && passedValidation) || (!propertyType && passedValidation)) { | ||
return true; | ||
@@ -202,3 +203,6 @@ } else { | ||
// | ||
function setter(value) { | ||
function setter(value) { | ||
if ((propertyType == "date") && (/[1-2][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9][0-9]Z/.test(value))) { | ||
value = new Date(value); | ||
} | ||
if (mask & Modeler.ARRAY) { | ||
@@ -205,0 +209,0 @@ if (!Array.isArray(value)) return; |
@@ -5,3 +5,3 @@ { | ||
"description": "A module for enforcing strict rules on object properties", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -1,2 +0,1 @@ | ||
This project aims to bring some level of data/type safety to NodeJS whilst allowing us to define clean data models. | ||
@@ -7,3 +6,3 @@ | ||
This is everything thrown together into one place for quick reference: | ||
```js | ||
var Modeler = require("../Modeler.js"); | ||
@@ -67,3 +66,2 @@ var className = 'MyClassName'; | ||
Modeler.register(ThisClass, className); | ||
``` |
@@ -5,3 +5,3 @@ var Modeler = require("../lib/Modeler.js"); | ||
var ThisClass = function(json) { | ||
var Address = function(json) { | ||
@@ -16,3 +16,3 @@ this.toString = function() { | ||
Modeler.extend(className, { | ||
Modeler.extend("Address", { | ||
Street: { | ||
@@ -52,3 +52,3 @@ type: "string", | ||
module.exports = ThisClass; | ||
Modeler.register(ThisClass, className); | ||
module.exports = Address; | ||
Modeler.register(Address, className); |
@@ -5,3 +5,3 @@ var Modeler = require("../lib/Modeler.js"); | ||
var ThisClass = function(json) { | ||
var Person = function(json) { | ||
// This class should provide an addAddress function | ||
@@ -19,3 +19,3 @@ this.addAddress = function(newAddress) { | ||
// This is the part which enforces rules on each property: | ||
Modeler.extend(className, { | ||
Modeler.extend("Person", { | ||
// We want a property called 'Title' | ||
@@ -93,2 +93,5 @@ Title: { | ||
} | ||
}, | ||
Age: { | ||
type: "number" | ||
} | ||
@@ -98,3 +101,3 @@ }, this, json); | ||
module.exports = ThisClass; | ||
Modeler.register(ThisClass, className); | ||
module.exports = Person; | ||
Modeler.register(Person, className); |
@@ -29,2 +29,4 @@ "use strict"; | ||
})); | ||
personA.Age = 24; | ||
personA.Age = "Fourty"; | ||
personA.Locations[0].doubleUpStreet(); | ||
@@ -45,2 +47,3 @@ personA.Expenses = ["105", "101.0", "106.00", 103, 104.0, 100.00]; | ||
assert.deepEqual(personA.Expenses, ['100.00', '101.00', '102.99', '103.00', '104.00', '105.00', '106.00'], "Expenses should be in order"); | ||
assert.equal(personA.Age, 24, "Person's Age should only accept numbers"); | ||
@@ -47,0 +50,0 @@ // |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22340
583
66