4.4.5 • Published 8 months ago

objectmodel v4.4.5

Weekly downloads
2,612
License
MIT
Repository
github
Last release
8 months ago

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.

4.4.5

8 months ago

4.4.3

1 year ago

4.4.2

1 year ago

4.4.4

1 year ago

4.4.1

1 year ago

4.4.0

1 year ago

4.3.1

2 years ago

4.3.0

3 years ago

4.2.3

3 years ago

4.2.2

4 years ago

4.2.1

4 years ago

4.2.0

4 years ago

4.1.0

4 years ago

4.0.6

4 years ago

4.0.5

4 years ago

4.0.4

4 years ago

4.0.3

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

5 years ago

3.7.7

5 years ago

3.7.6

5 years ago

3.7.5

6 years ago

3.7.4

6 years ago

3.7.3

6 years ago

3.7.2

6 years ago

3.7.1

6 years ago

3.7.0

6 years ago

3.6.0

6 years ago

3.5.4

6 years ago

3.5.3

6 years ago

2.6.4

6 years ago

3.5.2

6 years ago

3.5.1

6 years ago

2.6.3

6 years ago

3.5.0

6 years ago

3.4.6

6 years ago

3.4.5

6 years ago

3.4.4

6 years ago

3.4.3

6 years ago

3.4.2

6 years ago

3.4.1

6 years ago

3.4.0

6 years ago

3.3.0

6 years ago

3.2.2

6 years ago

3.2.1

6 years ago

3.2.0

6 years ago

3.1.2

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.6.2

7 years ago

2.6.1

7 years ago

2.6.0

7 years ago

2.5.4

7 years ago

2.5.3

7 years ago

2.5.2

7 years ago

2.5.1

7 years ago

2.5.0

7 years ago

2.4.5

8 years ago

2.4.4

8 years ago

2.4.3

8 years ago

2.4.2

8 years ago

2.4.1

8 years ago

2.4.0

8 years ago

2.3.2

8 years ago

2.3.1

8 years ago

2.3.0

8 years ago

2.2.0

8 years ago

2.1.2

8 years ago

2.1.1

8 years ago

2.1.0

8 years ago

2.0.1

8 years ago

1.2.0

8 years ago

2.0.0

8 years ago

1.1.5

8 years ago

1.1.4

8 years ago

1.1.3

8 years ago