The Wayback Machine - https://web.archive.org/web/20200521104453/https://github.com/sylvainpolletvillard/ObjectModel
Skip to content
Strong Dynamically Typed Object Modeling for JavaScript
JavaScript HTML CSS
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
build use cjs extension for build scripts Nov 20, 2019
dist update cjs to 4.2.1 May 14, 2020
docs upgrade deps Apr 2, 2020
src fix mutation in custom devtool formatter May 14, 2020
test add additional tests to basicmodel spec May 14, 2020
types remove model.validate Jan 2, 2019
.eslintignore eslintignore: ignore docs node_modules Nov 20, 2019
.eslintrc.json drop node <8 support Dec 20, 2018
.gitignore updated build Jul 18, 2018
.npmignore update npmignore - fix #115 Sep 5, 2019
.travis.yml use node v13 on travis ci Mar 1, 2020
CNAME added custom domain objectmodel.js.org Apr 11, 2015
LICENSE Initial commit on github - v0.6 Jan 11, 2015
README.md fix readme link Jun 29, 2017
index.html v4.2.1 May 14, 2020
package-lock.json use cjyes to provide a cjs version May 13, 2020
package.json add cjyes to build script May 14, 2020
rollup.config.js removed useless rollup name config Jun 17, 2019
tsconfig.json v3.2.2 Feb 11, 2018

README.md

Strong Dynamically Typed Object Modeling for JavaScript

Downloads Version Status License


What is this library ?

ObjectModel intends to bring strong dynamic type checking to your web applications. Contrary to static type-checking solutions like TypeScript or Flow, ObjectModel can also validate data at runtime: JSON from the server, form inputs, content from localStorage, external libraries...

By leveraging ES6 Proxies, this library ensures that your variables always match the model definition and validation constraints you added to them. Thanks to the generated exceptions, it will help you spot potential bugs and save you time spent on debugging. ObjectModel is also very easy to master: no new language to learn, no new tools, no compilation step, just a minimalist and intuitive API in a plain old JS micro-library.

Validating at runtime also brings many other benefits: you can define your own types, use them in complex model definitions with custom assertions that can even change depending on your application state. Actually it goes much further than just type safety. Go on and see for yourself.

Installation

Add the library to your project dependencies with NPM:

$ npm install objectmodel

or just download the library from Github

Basic usage example

import { ObjectModel } from "objectmodel"

const Order = new ObjectModel({
	product: { name: String, quantity: Number },
	orderDate: Date
});

const myOrder = new Order({
	product: { name: "Apple Pie", quantity: 1 },
	orderDate: new Date()
});

myOrder.product.quantity = 2; // no exceptions thrown
myOrder.product.quantity = false; //try to assign a Boolean
// ❌ TypeError: expecting product.quantity to be Number, got Boolean false

Documentation

For more examples, documentation and questions, please refer to the project website: objectmodel.js.org

Changelog and Release History

Please refer to Github Releases

Bug reports and pull requests are welcome.

Distributed under the MIT license. See LICENSE for more information.

You can’t perform that action at this time.