Strong Dynamically Typed Object Modeling for JavaScript
Model(definition, { sealed: true })
sealed
mode for object models to prevent undeclared propertiesimport { ObjectModel } from "objectmodel"
to enable tree shakingdelete
, defineProperty
or Object.keys
, are now checked against the model definition. Consequently, new type errors could be found after upgrading.Model.conventionForPrivate
and Model.conventionForConstant
have been moved to Model.prototype
so that you can change these conventions specifically by modelThis is almost a full rewrite of the library that I have been working on for over a year. ObjectModel is now written in ES6, has solid unit testing with over 400 assertions, and overall has much better mechanics to validate and cast your models. Enjoy !
path
information and have the same propertiesNaN
and Invalid Date
are now considered invalid for types Number
and Date
model.defaultTo
When constructing a composed object model, properties are automatically casted to model instances according to the definition. Now, this also works for union types. If several models are suitable within a union type, there is an ambiguity and the object will be left untouched with a warning console message.
See https://github.com/sylvainpolletvillard/ObjectModel/issues/24 for details
Model.prototype
, which enables you to add global assertionstrue
to validate. Truthy values do not pass anymoremodel.validate
and model.test