objectmodel 4.3.1 → 4.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +8 -8
- package/.eslintrc.json +25 -25
- package/.travis.yml +2 -2
- package/LICENSE +22 -22
- package/README.md +67 -67
- package/build/add-banner.js +13 -13
- package/build/bundle-entry.dev.js +2 -2
- package/build/bundle-entry.js +11 -11
- package/dist/object-model.cjs +462 -469
- package/dist/object-model.js +462 -469
- package/dist/object-model.js.map +1 -1
- package/dist/object-model.min.js +2 -2
- package/dist/object-model.min.js.map +1 -1
- package/index.html +4 -4
- package/package.json +9 -3
- package/rollup.config.js +13 -13
- package/src/array-model.d.ts +16 -0
- package/src/array-model.js +68 -68
- package/src/devtool-formatter.js +198 -198
- package/src/function-model.d.ts +24 -0
- package/src/function-model.js +58 -65
- package/src/helpers.js +43 -43
- package/src/index.js +4 -4
- package/src/list-model.js +43 -43
- package/src/map-model.d.ts +18 -0
- package/src/map-model.js +48 -48
- package/src/object-model.d.ts +74 -0
- package/src/set-model.d.ts +16 -0
- package/src/set-model.js +41 -41
- package/test/array-model.spec.cjs +291 -291
- package/test/array-model.test-d.ts +24 -0
- package/test/basic-model.spec.cjs +263 -263
- package/test/basic-model.test-d.ts +30 -0
- package/test/bench/array.html +51 -51
- package/test/bench/bench-lib.js +49 -49
- package/test/bench/map-no-cast.html +53 -53
- package/test/bench/map-set.html +52 -52
- package/test/bench/map.html +51 -51
- package/test/bench/object-models.html +87 -87
- package/test/function-model.spec.cjs +161 -162
- package/test/function-model.test-d.ts +18 -0
- package/test/index.cjs +13 -13
- package/test/map-model.spec.cjs +224 -224
- package/test/map-model.test-d.ts +21 -0
- package/test/model.spec.cjs +30 -30
- package/test/object-model.spec.cjs +1345 -1346
- package/test/object-model.test-d.ts +53 -0
- package/test/set-model.spec.cjs +213 -213
- package/test/set-model.test-d.ts +17 -0
- package/test/umd.html +25 -25
- package/types/definitions.d.ts +43 -0
- package/types/helpers.d.ts +4 -0
- package/types/index.d.ts +6 -128
package/.eslintignore
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
docs/examples/common.js
|
|
2
|
-
dist
|
|
3
|
-
test/lib
|
|
4
|
-
docs/**/lib
|
|
5
|
-
docs/v1
|
|
6
|
-
docs/v2
|
|
7
|
-
docs/node_modules
|
|
8
|
-
*.compiled.js
|
|
1
|
+
docs/examples/common.js
|
|
2
|
+
dist
|
|
3
|
+
test/lib
|
|
4
|
+
docs/**/lib
|
|
5
|
+
docs/v1
|
|
6
|
+
docs/v2
|
|
7
|
+
docs/node_modules
|
|
8
|
+
*.compiled.js
|
|
9
9
|
*.html
|
package/.eslintrc.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "eslint:recommended",
|
|
3
|
-
"env": {
|
|
4
|
-
"browser": true,
|
|
5
|
-
"node": true,
|
|
6
|
-
"es6": true
|
|
7
|
-
},
|
|
8
|
-
"parserOptions": {
|
|
9
|
-
"ecmaVersion": 2018,
|
|
10
|
-
"sourceType": "module"
|
|
11
|
-
},
|
|
12
|
-
"rules": {
|
|
13
|
-
"indent": [
|
|
14
|
-
"error",
|
|
15
|
-
"tab",
|
|
16
|
-
{
|
|
17
|
-
"SwitchCase": 1
|
|
18
|
-
}
|
|
19
|
-
],
|
|
20
|
-
"no-mixed-spaces-and-tabs": [
|
|
21
|
-
"error",
|
|
22
|
-
"smart-tabs"
|
|
23
|
-
],
|
|
24
|
-
"no-console": "off"
|
|
25
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"extends": "eslint:recommended",
|
|
3
|
+
"env": {
|
|
4
|
+
"browser": true,
|
|
5
|
+
"node": true,
|
|
6
|
+
"es6": true
|
|
7
|
+
},
|
|
8
|
+
"parserOptions": {
|
|
9
|
+
"ecmaVersion": 2018,
|
|
10
|
+
"sourceType": "module"
|
|
11
|
+
},
|
|
12
|
+
"rules": {
|
|
13
|
+
"indent": [
|
|
14
|
+
"error",
|
|
15
|
+
"tab",
|
|
16
|
+
{
|
|
17
|
+
"SwitchCase": 1
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"no-mixed-spaces-and-tabs": [
|
|
21
|
+
"error",
|
|
22
|
+
"smart-tabs"
|
|
23
|
+
],
|
|
24
|
+
"no-console": "off"
|
|
25
|
+
}
|
|
26
26
|
}
|
package/.travis.yml
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
language: node_js
|
|
2
|
-
node_js:
|
|
1
|
+
language: node_js
|
|
2
|
+
node_js:
|
|
3
3
|
- "13"
|
package/LICENSE
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
Copyright (c) 2015 Sylvain Pollet-Villard
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person
|
|
4
|
-
obtaining a copy of this software and associated documentation
|
|
5
|
-
files (the "Software"), to deal in the Software without
|
|
6
|
-
restriction, including without limitation the rights to use,
|
|
7
|
-
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
copies of the Software, and to permit persons to whom the
|
|
9
|
-
Software is furnished to do so, subject to the following
|
|
10
|
-
conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be
|
|
13
|
-
included in all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
-
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
-
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
-
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
-
OTHER DEALINGS IN THE SOFTWARE.
|
|
1
|
+
Copyright (c) 2015 Sylvain Pollet-Villard
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
|
4
|
+
obtaining a copy of this software and associated documentation
|
|
5
|
+
files (the "Software"), to deal in the Software without
|
|
6
|
+
restriction, including without limitation the rights to use,
|
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the
|
|
9
|
+
Software is furnished to do so, subject to the following
|
|
10
|
+
conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
<p align="center"><a href="http://objectmodel.js.org" target="_blank"><img width="400" src="http://objectmodel.js.org/docs/res/logo.png"></a></p>
|
|
2
|
-
|
|
3
|
-
<p align="center">Strong Dynamically Typed Object Modeling for JavaScript</p>
|
|
4
|
-
<p align="center">
|
|
5
|
-
<a href="https://www.npmjs.com/package/objectmodel"><img src="https://img.shields.io/npm/dt/objectmodel.svg" alt="Downloads"></a>
|
|
6
|
-
<a href="https://www.npmjs.com/package/objectmodel"><img src="https://img.shields.io/npm/v/objectmodel.svg" alt="Version"></a>
|
|
7
|
-
<a href="https://travis-ci.org/sylvainpolletvillard/ObjectModel"><img src="https://travis-ci.org/sylvainpolletvillard/ObjectModel.svg?branch=master" alt="Status"></a>
|
|
8
|
-
<a href="https://www.npmjs.com/package/objectmodel"><img src="https://img.shields.io/npm/l/objectmodel.svg" alt="License"></a>
|
|
9
|
-
</p>
|
|
10
|
-
|
|
11
|
-
---
|
|
12
|
-
|
|
13
|
-
## What is this library ?
|
|
14
|
-
|
|
15
|
-
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...
|
|
16
|
-
|
|
17
|
-
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*.
|
|
18
|
-
|
|
19
|
-
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.
|
|
20
|
-
|
|
21
|
-
## Installation
|
|
22
|
-
Add the library to your project dependencies with NPM:
|
|
23
|
-
```bash
|
|
24
|
-
$ npm install objectmodel
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
or just [download the library from Github][github-releases]
|
|
28
|
-
|
|
29
|
-
## Basic usage example
|
|
30
|
-
|
|
31
|
-
```javascript
|
|
32
|
-
import { ObjectModel } from "objectmodel"
|
|
33
|
-
|
|
34
|
-
const Order = new ObjectModel({
|
|
35
|
-
product: { name: String, quantity: Number },
|
|
36
|
-
orderDate: Date
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const myOrder = new Order({
|
|
40
|
-
product: { name: "Apple Pie", quantity: 1 },
|
|
41
|
-
orderDate: new Date()
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
myOrder.product.quantity = 2; // no exceptions thrown
|
|
45
|
-
myOrder.product.quantity = false; //try to assign a Boolean
|
|
46
|
-
// ❌ TypeError: expecting product.quantity to be Number, got Boolean false
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## Documentation
|
|
50
|
-
|
|
51
|
-
For more examples, documentation and questions, please refer to the project website: [objectmodel.js.org][website]
|
|
52
|
-
|
|
53
|
-
## Changelog and Release History
|
|
54
|
-
|
|
55
|
-
Please refer to [Github Releases][github-releases]
|
|
56
|
-
|
|
57
|
-
*Bug reports and pull requests are welcome.*
|
|
58
|
-
|
|
59
|
-
Distributed under the MIT license. See ``LICENSE`` for more information.
|
|
60
|
-
|
|
61
|
-
[website]:http://objectmodel.js.org
|
|
62
|
-
[TypeScript]:https://www.typescriptlang.org/
|
|
63
|
-
[Flow]:https://flowtype.org/
|
|
64
|
-
[github-releases]:https://github.com/sylvainpolletvillard/ObjectModel/releases
|
|
65
|
-
[npm-url]: https://npmjs.org/package/objectmodel
|
|
66
|
-
[npm-image]: https://img.shields.io/npm/v/objectmodel.svg
|
|
67
|
-
[npm-downloads]: https://img.shields.io/npm/dm/objectmodel.svg
|
|
1
|
+
<p align="center"><a href="http://objectmodel.js.org" target="_blank"><img width="400" src="http://objectmodel.js.org/docs/res/logo.png"></a></p>
|
|
2
|
+
|
|
3
|
+
<p align="center">Strong Dynamically Typed Object Modeling for JavaScript</p>
|
|
4
|
+
<p align="center">
|
|
5
|
+
<a href="https://www.npmjs.com/package/objectmodel"><img src="https://img.shields.io/npm/dt/objectmodel.svg" alt="Downloads"></a>
|
|
6
|
+
<a href="https://www.npmjs.com/package/objectmodel"><img src="https://img.shields.io/npm/v/objectmodel.svg" alt="Version"></a>
|
|
7
|
+
<a href="https://travis-ci.org/sylvainpolletvillard/ObjectModel"><img src="https://travis-ci.org/sylvainpolletvillard/ObjectModel.svg?branch=master" alt="Status"></a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/objectmodel"><img src="https://img.shields.io/npm/l/objectmodel.svg" alt="License"></a>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## What is this library ?
|
|
14
|
+
|
|
15
|
+
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...
|
|
16
|
+
|
|
17
|
+
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*.
|
|
18
|
+
|
|
19
|
+
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.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
Add the library to your project dependencies with NPM:
|
|
23
|
+
```bash
|
|
24
|
+
$ npm install objectmodel
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
or just [download the library from Github][github-releases]
|
|
28
|
+
|
|
29
|
+
## Basic usage example
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
import { ObjectModel } from "objectmodel"
|
|
33
|
+
|
|
34
|
+
const Order = new ObjectModel({
|
|
35
|
+
product: { name: String, quantity: Number },
|
|
36
|
+
orderDate: Date
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const myOrder = new Order({
|
|
40
|
+
product: { name: "Apple Pie", quantity: 1 },
|
|
41
|
+
orderDate: new Date()
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
myOrder.product.quantity = 2; // no exceptions thrown
|
|
45
|
+
myOrder.product.quantity = false; //try to assign a Boolean
|
|
46
|
+
// ❌ TypeError: expecting product.quantity to be Number, got Boolean false
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Documentation
|
|
50
|
+
|
|
51
|
+
For more examples, documentation and questions, please refer to the project website: [objectmodel.js.org][website]
|
|
52
|
+
|
|
53
|
+
## Changelog and Release History
|
|
54
|
+
|
|
55
|
+
Please refer to [Github Releases][github-releases]
|
|
56
|
+
|
|
57
|
+
*Bug reports and pull requests are welcome.*
|
|
58
|
+
|
|
59
|
+
Distributed under the MIT license. See ``LICENSE`` for more information.
|
|
60
|
+
|
|
61
|
+
[website]:http://objectmodel.js.org
|
|
62
|
+
[TypeScript]:https://www.typescriptlang.org/
|
|
63
|
+
[Flow]:https://flowtype.org/
|
|
64
|
+
[github-releases]:https://github.com/sylvainpolletvillard/ObjectModel/releases
|
|
65
|
+
[npm-url]: https://npmjs.org/package/objectmodel
|
|
66
|
+
[npm-image]: https://img.shields.io/npm/v/objectmodel.svg
|
|
67
|
+
[npm-downloads]: https://img.shields.io/npm/dm/objectmodel.svg
|
|
68
68
|
[license-badge]:https://img.shields.io/badge/license-MIT-blue.svg
|
package/build/add-banner.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import fs from 'fs';
|
|
2
|
-
import pkg from '../package.json' assert { type: 'json' };
|
|
3
|
-
|
|
4
|
-
const banner = `// ObjectModel v${pkg.version} - ${pkg.homepage}
|
|
5
|
-
// ${pkg.license} License - ${pkg.author}`;
|
|
6
|
-
|
|
7
|
-
const paths = [
|
|
8
|
-
"./dist/object-model.js",
|
|
9
|
-
"./dist/object-model.min.js"
|
|
10
|
-
]
|
|
11
|
-
|
|
12
|
-
paths.forEach(path => {
|
|
13
|
-
fs.writeFileSync(path, banner + '\n' + fs.readFileSync(path, 'utf8'))
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import pkg from '../package.json' assert { type: 'json' };
|
|
3
|
+
|
|
4
|
+
const banner = `// ObjectModel v${pkg.version} - ${pkg.homepage}
|
|
5
|
+
// ${pkg.license} License - ${pkg.author}`;
|
|
6
|
+
|
|
7
|
+
const paths = [
|
|
8
|
+
"./dist/object-model.js",
|
|
9
|
+
"./dist/object-model.min.js"
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
paths.forEach(path => {
|
|
13
|
+
fs.writeFileSync(path, banner + '\n' + fs.readFileSync(path, 'utf8'))
|
|
14
14
|
})
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import "../src/devtool-formatter"
|
|
2
|
-
|
|
1
|
+
import "../src/devtool-formatter"
|
|
2
|
+
|
|
3
3
|
export * from "./bundle-entry"
|
package/build/bundle-entry.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Model, BasicModel, ObjectModel, ArrayModel, FunctionModel, MapModel, SetModel, Any } from "../src/index"
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
Model,
|
|
5
|
-
BasicModel,
|
|
6
|
-
ObjectModel,
|
|
7
|
-
ArrayModel,
|
|
8
|
-
FunctionModel,
|
|
9
|
-
MapModel,
|
|
10
|
-
SetModel,
|
|
11
|
-
Any
|
|
1
|
+
import { Model, BasicModel, ObjectModel, ArrayModel, FunctionModel, MapModel, SetModel, Any } from "../src/index"
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
Model,
|
|
5
|
+
BasicModel,
|
|
6
|
+
ObjectModel,
|
|
7
|
+
ArrayModel,
|
|
8
|
+
FunctionModel,
|
|
9
|
+
MapModel,
|
|
10
|
+
SetModel,
|
|
11
|
+
Any
|
|
12
12
|
}
|