I would like to declare objects schemas (that can instantiate variables with default values, having validation rules, etc.) like it can be done in mongoose, but on the client-side.
Haven't found any library offering it. Is there something I missed?
I would like to declare objects schemas (that can instantiate variables with default values, having validation rules, etc.) like it can be done in mongoose, but on the client-side.
Haven't found any library offering it. Is there something I missed?
visit https://github.com/spumko/joi and I think you'll find a lot of joy[i].
The joi validation system is used to validate JavaScript objects based on a rich descriptive schema. Schema validation is the process of ensuring that objects match pre-defined expectations.
I mainly use it with nodejs but I think you'll find it nice also to use on the client side with http://browserify.org/.
To solve this problem I created https://github.com/archangel-irk/storage
Mongoose-like schema validation, collections and documents on browser.
Forms-angular: http://www.forms-angular.org/
You can describe schema at the client side level (part of schemas or nested schemas/ arrays of subdocuments ...) and forms with validators are automatically generated.
Moreover, you can just define mongoose schemas at the backend level and you end up with a great front-end/backend system for creating/loading/editing/deleting items in a mongo db.
edit: This library might be what you are looking for: https://github.com/molnarg/js-schema
What you are describing is essentially what classes
do in languages such as java, c++, objective-c, etc. Unfortunately javascript doesn't really offer this functionality. The closest thing you can do is implementing Prototypes
:
How does JavaScript .prototype work?
edit: on second thought, with Prototypes
you should be able to achieve everything you asked for